selectedIndex:返回或设置下列类表中被选中项的索引; size:下拉列表可见的数目;
add(newOption,后面的option):增加一个选项,两个参数均是必须的; remove(i):删除索引为i的元素。
2.option的属性和方法
index:返回下列列表中某个选项的索引位置;selected=true|false:返回某个选项是否被选中
select.options[i].text:返回某个选项的文本值;select.options[i].value:返回选项i的值
3.添加新的选项的方法
3.1 通过DOM
var newOption = document.createElement('option'); newOption.setAttribute('value','option value'); newOption.appendChild(document.createElement('option text')) selectBox.appendChild(newOption);
3.2 通过add
var newOption = new Option('option text','option value'); selectBox(newOption,undefined);
4.可添加的下拉列表
1.直接在下拉列表中添加
<div> <select id="select" > <option ></option> <option value="11" selected>北京</option> <option value="22">上海</option> <option value="33">武汉</option> </select> </div> (function(){ var select = document.getElementById('select'); select.onkeydown = function(e){ e = e||window.event; if(e.keyCode ===8){ this.options[0].text = this.options[0].text.slice(0,this.options[0].text.length>0?this.options[0].text.length-1:0); }else{ this.options[0].selected = true; this.options[0].text += String.fromCharCode(e.keyCode); } } })()
2.通过文本框添加
<div> <select id="select" > <option value="11">北京</option> <option value="22">上海</option> <option value="33">武汉</option> </select> <label for="add">添加</label><input type="text" id="add" /> <input type="button" value="添加" id="mybutton" /> </div> (function(){ var mybtn = document.getElementById('mybutton'); mybtn.onclick = function(){ var select = document.getElementById('select'); var txt = document.getElementById('add').value; var a = new Option(txt,txt); select.add(a,select[0]); } })()
相关推荐
SQL语句select用法详解
select into 和 insert into select 两种表复制语句 第一句(select into from)要求目标表(destTbl)不存在,因为在插入时会自动创建 第二句(insert into select from)要求目标表(destTbl)存在,由于目标表...
linux下select和poll的用法,关于设备驱动程序中的select和poll函数的用法。
select 的另类用法select 的另类用法select 的另类用法select 的另类用法select 的另类用法
很好的Select用法详解,看看还挺实用的,多谢各位大力相助,小弟才能在此与哥相遇,谢谢各位了
html:select>标签的用法 <html:select property="theChoice"> </html:select>
Oracle中没有select into的用法! 在某些数据库中有select into的用法,用法是: select valueA,valueB into tableB from tableA; 上面这句语句的意思是将tableA表中的valueA和valueB字段的值和结构添加到tableB中,...
linux shell 编程中select 命令的用法
简要介绍了select语句的用途已经详细介绍了select的使用方法,为初学者提供借鉴
SQL Select 命令是自 FoxPro 2.5 以来实现的嵌入式 SQL。一条合理的 SQL Select 命令对于数据的查询速度要远远快于 FoxPro 的过程性代码。ANSI/ISO 标准定义了 SQL Select 各子句的实现方式,因此 FoxPro 中写的 SQL...
SQL语句 SELECT LIKE like用法详解SQL语句 SELECT LIKE like用法详解SQL语句 SELECT LIKE like用法详解
本文主要给大家介绍了Angular2中select用法之设置默认值与事件的相关内容,分享出来供大家参考学习,下面来看看详细的介绍: 一、设置默认值: 现在有三个学生小明,小红,小黑,对双向绑定的student设置你想要的...
美化HTML的select标签的原始样式,并且不影响原始select的事件方法调用。
网上搜索的,略加整理。
select的用法举例,适合初学者使用。
WDA中select option的用法
SELECT语句使用大全 SELECT语句使用大全 SELECT语句使用大全
SELECT语句高级用法1,使用group by 子句group by 子句将表分为几组,此子句通常与为每个这样的组生产总结值的聚集函数组合。使用不带聚集的group by 子句与在select 子句中使用的distinct(或unique)关键字很相 ...
C--网络编程SELECT函数用法详解