combox.options[i] = null //Remove item from combox

解决方案 »

  1.   

    这样应该是可以的:
    for(i=0;i<combox.options.length;i++){
           combox.options[i]=null
    }
      

  2.   

    将kevinsea(kevinsea) 的代码改为
    for(i=0;i<combox.options.length;i++){
          combox.options[0]=null
    }
    只要对第一个元素清空就可以了,下面的元素会一一变为第一个元素而被清空
      

  3.   

    document.formname.selectname.options.length = 0;
      

  4.   

    it should work,<script language="javascript">
    function clean()
    {
     // document.frm1.sel1.options.length = 0;
      var opts = document.frm1.sel1.options;
      while (opts.length > 0)
    opts.remove(0);
    }
    </script>
      

  5.   

    这次一定是可以的。
    function EmptyOption(){
    var temp=combox.options.length;
    for(i=0;i<temp;i++){
          combox.options[0]=null
    }
    }
    </script>
      

  6.   

    <select name=a2>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    </select>g = a2.length;
    for (var i=0;i<g;i++)
    {
    a2[0] = null;
    }for (var i=0;i<a2.length;i++),直接这么写运行时是这个样子的
    假设开始有5个
    先去了第零个然后a2.length变成了4,i变成了1
    去第一个a2.length变成了3,i变成了2
    去第三个的时候已经不执行循环了,这样一看,只能去掉一半(奇数时是一半加一),因为循环只执行了一半的次数
      

  7.   

    <select name=a2>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    <option>asdf</option>
    </select>g = a2.length;
    for (var i=0;i<g;i++)
    {
    a2[0] = null;
    }for (var i=0;i<a2.length;i++),直接这么写运行时是这个样子的
    假设开始有5个
    先去了第零个然后a2.length变成了4,i变成了1
    去第一个a2.length变成了3,i变成了2
    去第三个的时候已经不执行循环了,这样一看,只能去掉一半(奇数时是一半加一),因为循环只执行了一半的次数
      

  8.   

    谢谢各位,我犯了一个低级错误,我把 length写为lenth了,好不容易发现了,呵呵,
    给各位加分了