操作select的问题,在线等,立即结贴
<form name= "tfrom ">
<select name= "cati ">
<option value= "01 "> 我 </option>
<option value= "02 "> 你 </option>
<option value= "03 "> 他 </option>
</select> </form>
现在我有值为 a = '03 ' 怎么用 javascript 来让 value = 03 的项被选中?
------解决方案-------------------- <script>
function a(val){
for (var i =0; i <document.forms[0].cati.options.length; i++){
if (document.forms[0].cati.options[i].value == val){
document.forms[0].cati.options[i].selected = true;
break;
}
}
}
</script>
</head>
<body onload= "a( '02 '); ">
<form name= "tfrom ">
<select name= "cati ">
<option value= "01 "> 我 </option>
<option value= "02 "> 你 </option>
<option value= "03 "> 他 </option>
</select> </form>
</body>
------解决方案-------------------- <html>
<head>
<script defer>
var a= '03 ';
document.all.cati.value=a;
</script>
</head>
<body>
<form name= "tfrom ">
<select name= "cati ">
<option value= "01 "> 我 </option>
<option value= "02 "> 你 </option>
<option value= "03 "> 他 </option>
</select> </form>
</body>
</html>