javascript改变列表框选中值,帮忙改得兼容firefox

来源:百度知道 编辑:UC知道 时间:2024/09/21 20:31:22
以下代码在IE里可行,但在FIREFOX里不行,帮忙改一下,很重要的。谢谢!
<script language="javascript">
function a(str){
select=document.form1.s1;
for(x=0;x<select.children.length;x++){
var child=select.children[x];
if(child.value===str){
child.selected=true;
}
}
}

</script>
<form id="form1" name="form1" method="post" action="">
<select name="s1" id="s1">
<option value="">选择</option>
<option value="中国">中国</option>
<option value="美国">美国</option>
<option value="英国">英国</option>
</select>
<input type="button" name="button" id="button" value="中国" onclick="a('中国')" />
<input type="button" name="button" id="but

<script language="javascript">
function a(str){
slt=document.getElementById("s1").getElementsByTagName("option");
for(i=0;i<slt.length;i++){
if(slt[i].value==str){slt[i].selected="selected";break;}

}
}

</script>
<form id="form1" name="form1" method="post" action="">
<select name="s1" id="s1">
<option value="">选择</option>
<option value="中国">中国</option>
<option value="美国">美国</option>
<option value="英国">英国</option>
</select>
<input type="button" name="button" id="button" value="中国" onclick="a(this.value)" />
<input type="button" name="button" id="button" value="美国&quo