有点小问题,第一次会把原来的选项“333”覆盖掉,并且会多出来一项“Other..”,但是实际使用当中似乎这个Other选项没有什么作用。

解决方案 »

  1.   

    like this?
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>New Page 1</title>
    </head>
    <script>
    function selectOther(list) {
    var input = document.createElement("INPUT");
    input.className = "select";
    input.type = "text";
    input.onblur = function() {
    var list = this.oldNode;
    list.options[list.options.length - 1] = new Option(this.value, "", true);
    list.options[list.options.length] = new Option("Other...");
    list.selectedIndex = list.options.length - 2;this.parentNode.replaceChild(list, this);
    };
    input.oldNode = list.parentNode.replaceChild(input, list);
    }
    </script>
    <body>
      <p><select size="1" name="D1" onchange="if(this.selectedIndex==this.options.length-1)selectOther(D1)">
      <option>111</option>
        <option>222</option>
          <option>333</option>
    <option>Other...</option>
      </select>
    </p>
    </body>
    </html>