怎么用JS来控制<select>那个项目选项定
<form method= "post " name= "form ">
<input type= "text " name= "temp " size= "30 ">
<select name= "Class_1 " style= "width:80px " onchange= "temp.value=this.value ">
</select>
</form>
<script LANGUAGE= "javascript ">
document.form.Class_1.length = 0;
document.form.Class_1.options[document.form.Class_1.length] = new Option( '王一蛋 ', '1 ');
document.form.Class_1.options[document.form.Class_1.length] = new Option( '王二蛋 ', '2 ');
document.form.Class_1.options[document.form.Class_1.length] = new Option( '王三蛋 ', '3 ');
document.form.Class_1.options[document.form.Class_1.length] = new Option( '王四蛋 ', '4 ');
document.form.Class_1.options[document.form.Class_1.length] = new Option( '王五蛋 ', '5 ');
document.form.Class_1.options[document.form.Class_1.length] = new Option( '王六蛋 ', '6 ');
document.form.Class_1.options[document.form.Class_1.length] = new Option( '王七蛋 ', '7 ');
document.form.Class_1.options[document.form.Class_1.length] = new Option( '王八蛋 ', '8 ');
/////////这句应该怎么写才能让王七蛋处理选定状态(不要index值控制)//////////
document.form.Class_1.options.text[ '王七蛋 '].selected=true;
//////////////////////////////
</script>
------解决方案-------------------- <form method= "post " name= "form ">
<input type= "text " name= "temp " size= "30 ">
<select name= "Class_1 " style= "width:80px " onchange= "temp.value=this.value ">
</select>
</form>
<script LANGUAGE= "javascript ">
var arr = [
[ ' ', '0 '],
[ '王一蛋 ', '1 '],
[ '王二蛋 ', '2 '],
[ '王三蛋 ', '3 '],
[ '王四蛋 ', '4 '],
[ '王五蛋 ', '5 '],
[ '王六蛋 ', '6 '],
[ '王七蛋 ', '7 '],
[ '王八蛋 ', '8 ']
]
function createSelect(val){
for (var i = 0; i < arr.length; i++){
document.form.Class_1.options[i] = new Option(arr[i][0], arr[i][1]);
if (arr[i][0] == val){
document.form.Class_1.options[i].selected = true;
}
}
}
createSelect( '王七蛋 ');
</script>
------解决方案--------------------不太懂JS,帮顶,楼上老大应该不错