您现在的位置是:首页 > 电脑技术查询 > web开发

删除选择框的选项,怎么在Mozilla浏览器下运行

编辑:chaxungu时间:2022-10-02 23:21:23分类:web开发

删除选择框的选项,如何在Mozilla浏览器下运行
function delAllSelectOption(SelectName,win)
{//设置Select选择框的值,win是窗口对象
if(win==null)win=window
with(win)
{
var Selectobj = eval( "document.forms[0]. "+SelectName);
for(var i=Selectobj.options.length;i> 0;i--)
{Selectobj.options.remove(i-1)}
}
}

如题,这个函数要在Mozilla下如何调整?remove函数貌似只能在IE下运行。

------解决方案--------------------
for(var i=Selectobj.childNodes.length;i> 0;i--)
{
Selectobj.removeChild(Selectobj.childNodes[i-1]);
}
------解决方案--------------------
Selectobj.length = -1;
------解决方案--------------------
<select id= "sel ">
</select>
<script type= "text/javascript ">
// <![CDATA[
var a=document.getElementById( "sel ");
var o=new Option( "never-online ", "a ",false,false);
a.options.add(o);
alert( "你可以看到添加了never-online这个option ");
a.remove(0);
alert( "现在删除添加的option ");
//]]>
</script>