急,如何在JAVASCRIPT中让一个自动添加<option>的多选的下拉列表出来就处于全选状态
急,如何在JAVASCRIPT中让一个自动添加 <option> 的多选的下拉列表出来就处于全选状态,
各位大侠,帮忙罗.谢了.
[解决办法]
<select id= "s " multiple= "true ">
<option> 1 </option>
<option> 2 </option>
<option> 3 </option>
<option> 4 </option>
</select>
<input type= "button " value= "select all " onclick= "sa(true); ">
<input type= "button " value= "unselect all " onclick= "sa(false); ">
<script language= "javascript ">
function sa(flag){
var obj = document.getElementById( "s ");
for(var i=0;i <obj.options.length;i++){
obj.options[i].selected = flag?true:false;
}
}
</script>