81,092
社区成员
发帖
与我相关
我的任务
分享
function a(){
//需要实现控制可以加if() while()实现
alert("111");
}
<select id= 'a ' name= 'a ' onchange= "a()">
<option value= 'a ' seleted> a </option>
<option value= 'b '> b </option>
<option value= 'c '> c </option>
</select>
<BODY>
<select id= 'a' name= 'a ' onchange= a(this)>
<option value= 'a ' seleted> a </option>
<option value= 'b '> b </option>
<option value= 'c '> c </option>
</select>
</BODY>
<script language= 'javascript'/>
function a(s){
alert(s.selectedIndex);
}
document.getElementById('a').options[1].selected=true;
a(document.getElementById("a"));
</script>
<select id= 'a ' name= 'a ' onchange= 'javascript:a(); '>
<option value= 'a ' seleted> a </option>
<option value= 'b '> b </option>
<option value= 'c '> c </option>
</select>
请问要怎样用js触发select的onchange事件?下面是我出错的代码
<script language= 'javascript '>
document.getElementById( "a ").options[2].selected=true;
document.getElementById( "a ").change();
</script>