Summary of various ways in which javascript removes the option option
- 2020-03-29 23:58:57
- OfStack
1, JavaScript,
2, JavaScript,
3, JavaScript,
4, JavaScript,
RemoveOption Usage in ie
RemoveOption Use in FF
var oSel=document.form1.DropDownCity;
while(oSel.options.length>0){
oSel.removeChild(oSel.options[0]);
}
2, JavaScript,
<SCRIPT LANGUAGE="JavaScript">
function del1(){
var obj = document.getElementById("s");
var count = obj.options.length;
for(var i = 0;i<count;i++){
obj.options.remove(0);//Each time I delete the index, I get 0
}
}
</SCRIPT>
3, JavaScript,
<script language="javascript">
function del() {
for (var i = s.options.length - 1; i >= 0; i --)
s.options[i] = null;
}
</script>
4, JavaScript,
<SCRIPT LANGUAGE="JavaScript">
function del1(){
var obj = document.getElementById("s");
obj.options.length=0
}
</SCRIPT>
RemoveOption Usage in ie
function removeOption(index)
{
document.getElementById("selUnassignedUsers").options.remove(index);
}
RemoveOption Use in FF
function removeOption(index)
{
document.getElementById("selUnassignedUsers").remove(index);
}