欢迎加入站点基地设计开发交流群:30720409
详细内容
html里下拉列表的操作说明
发布日期:2010-06-26     点击:4467     字体:[ ]

<form id="f">
          <select size="1" name="s">
                          <option value=www.zdbase.com>站点基地</option>
                          <option value="zdbase.com">网站素材</option>
          </select>
</form>
<script type="text/javascript" language="javascript">
<!--
var f = document.getElementById("f");
//列表项数目(有两种方法)
document.write(f.s.options.length);
document.write(f.s.length);
//当前选中项的下标(从 0 开始)(有两种方法)
//如果选择了多项,则返回第一个选中项的下标
document.write(f.s.options.selectedIndex);
document.write(f.s.selectedIndex);
//检测某一项是否被选中
document.write(f.s.options[0].selected);
//获得某一项的值和文字
document.write(f.s.options[0].value);
document.write(f.s.options[1].text);
//删除某一项
f.s.options[1] = null;
//追加一项
f.s.options[f.s.options.length] = new Option("追加的text", "追加的value");
//更改一项
f.s.options[1] = new Option("更改的text", "更改的value");
//也可以直接设置该项的 text 和 value
//-->
</script>

======================

<select name="a">
      <option value="">pls select</option>
      <option value="1">aaaa1</option>
      <option value="2">aaaa2</option>
      <option value="3">aaaa3</option>
      <option value="4">aaaa4</option>
</select>
<input type="button" onclick="remove()" value="remove">
<input type="button" onclick="add()" value="add">
<script language="javascript">
      function remove(){
          var obj = document.getElementById("a")
          while(obj.length>1)
          {
              obj.options.remove(obj.length-1)
          }
      }
    
      function add(){
          var obj = document.getElementById("a")        
          for(i=1;i<5;i++)
          {
              var option = document.createElement("option")
              obj.options.add(option)
              obj.options[i].text = "aaaa"+i;
              obj.options[i].value = i;
          }
      }
</script>

用户评论
昵称 
内容  *
验证码   
   
Copyright © 2010 zdbase.com All Rights Reserved. 苏ICP备15039389号-1 可人软件设计