怎么用Javascript清除掉Select表单里的所有元素? <input type=button onclick="abc.length=0"> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 document.getElementById("abc").options.length=0 <script type="text/javascript">//<![CDATA[ window.onload=function(){ document.all.abc.length=0; }//]]></script> document.getElementById("abc").options.length=0 document.getElementById("abc").options.length=0书上说:这样可以 首先推荐你用id来标识<select id="abc"> <option value="a">a</option> <option value="b">b</option> </select><script language="javascript">var clearSelectById = function(){var obj = document.getElementById('abc');var list =obj.childNodes;for( var i in list){obj.removeNode(list[i]);}}</script><a href="javascript:void(0);" onclick="clearSelectById();">删除</a> 懒狗的方法好.有dom的概念哦. document.getElementById("abc").options.length=0这个是正解 方法一://注意:清除下拉列表框中的各项用removeChild(document.form1.abc.options[0])函数,//为什么老是只清除document.form1.abc.options[0]第一项呢?因为为我们清除一项时,第二项会自动上移一项,这也就是为什么老是只清除第一项的原因for(var j=0;j<document.form1.abc.options.length;j++)//先清除原来的{document.form1.abc.options.removeChil(document.form1.abc.options[1]);}方法二:obj.options.length = 0 <script language="Javascript"> function Remove(){ var objsel = document.getElementById("lbReady"); for(var i = objsel.options.length - 1 ;i >= 0;i--) { if(objsel.options[i].selected) { objsel.remove(i) } }return false; }</script> 对于Array 和 Array-like ,都可以用设置length=n的方法,保留前n个元素,后边的被解释器回收 问一个checkbox点中后自动选中此类别下子选项checkbox的问题 weblogic 12c中ext js树显示不了 正则表达式[\s\S]*?在RegExp中的问题 怎样实现文本框替换成下拉框 没有办法访问到b函数吗? 下拉菜单实现页面定位的问题。 中文排序的问题 俺们做的3D GIS 客户端控件,欢迎试用 如何打开一个子窗口,其子窗口的html代码是在父窗口生成的? 怎样在javascrip的函数里不打开另外的窗口,而执行一个php或asp程序。 鼠标移动上去变换图片,鼠标移开还原如何实现? 下载了个Aptana IDE,但是使用一段时间,javaw.exe老占内存95%~98%
//<![CDATA[
window.onload=function(){
document.all.abc.length=0;
}
//]]>
</script>
<option value="a">a</option>
<option value="b">b</option>
</select><script language="javascript">var clearSelectById = function(){
var obj = document.getElementById('abc');var list =obj.childNodes;
for( var i in list){
obj.removeNode(list[i]);}
}
</script>
<a href="javascript:void(0);" onclick="clearSelectById();">删除</a>
这个是正解
//注意:清除下拉列表框中的各项用removeChild(document.form1.abc.options[0])函数,
//为什么老是只清除document.form1.abc.options[0]第一项呢?因为为我们清除一项时,第二项会自动上移一项,这也就是为什么老是只清除第一项的原因
for(var j=0;j<document.form1.abc.options.length;j++)//先清除原来的
{
document.form1.abc.options.removeChil(document.form1.abc.options[1]);
}方法二:obj.options.length = 0
function Remove()
{
var objsel = document.getElementById("lbReady"); for(var i = objsel.options.length - 1 ;i >= 0;i--)
{
if(objsel.options[i].selected)
{
objsel.remove(i)
}
}
return false;
}
</script>