<select name="type" οnchange="show_sub(this)">
<option value="0">请选择主菜名</option>
<option value="1">白菜</option>
<option value="2">萝卜</option>
</select>
js代码比较简单
<script>
function mode(obj){
var opt = obj.options[obj.selectedIndex]
opt.text === //白菜
opt.value === //1
opt.value == obj.value
obj.text obj.key 不存在
}
</script>
最重要的知识点是获在select οnchange="test(this)"的this获取option的value值:this.options[this.options.selectedIndex].value ====== this.value
this ==== console.log(this) 打印出来是select 全部标签
最重要的知识点是通过form的οnsubmit="return check(this)"的this值获取option的value值:
//this=== console.log(this) 打印出的就是这个form表单
this.template_id===等于上面的那个this;// template_id 是select的name值,这么获取form下的select全部标签
this.template_id.value //这么获取form下的select的选中值