当前位置: 代码迷 >> JavaScript >> JS怎么清空下拉框的值
  详细解决方案

JS怎么清空下拉框的值

热度:128   发布时间:2012-05-31 12:19:24.0
JS如何清空下拉框的值
JS如何清空下拉框的值

------解决方案--------------------
不能清空,但可以设置为指定的选项。
HTML code
<select id="demo">
    <option value="1">111</option>
    <option value="2">222</option>
</select>

<button id="btn">设置为默认值</button>
<script type="text/javascript">
document.getElementById('btn').onclick = function() { document.getElementById('demo').selectedIndex = 0; }
</script>

------解决方案--------------------
HTML code



var ter= document.getElementById("term");

         ter.length=1;

         //重新新加
         //ter.options.add(new Option("12个月","12"));
         //ter.options.add(new Option("24个月","24"));
         //ter.options.add(new Option("36个月","36"));
         //ter.options.add(new Option("48个月","48"));
         //ter.options.add(new Option("60个月","60")); 
  相关解决方案