Option操作呀。
来源:互联网 发布:fdd lte网络优化手段 编辑:程序博客网 时间:2024/05/01 18:48
Md 昨天写的太长了 结果没有保存住,只好今天重写了, 太阳呀。。。
1)清空options
obj.options.length=0
<script>
function ss()
{document.getElementById("gg").options.length=0}
</script>
<select id="gg"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<input value="清空" type="button" onClick="ss()">
2)删除一项option
obj.remove(Index)
<script>
function ss(num)
{document.getElementById("gg").remove(num)
document.getElementById("gg").selectedIndex=0 }
</script>
<select id="gg"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<input id="ff" type="text">
<input value="清空" type="button" onClick="ss(document.getElementById('ff').value)">
3)创建一项option
var option =new Option(text,value) //后面的O要大写。。。。
4)添加一项option
obj.options.add(new Option(text,vakue))
<script>
function ss(num)
{ var option =new Option("Hi",1)
document.getElementById("gg").options.add(option)}
</script>
<select id="gg"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<input value="添加" type="button" onClick="ss()">
5)修改一项option
obj.options[num]=new Option(text,value)
<script>
function ss()
{ document.getElementById("gg").options[1] = new Option("你好",1);
document.getElementById("gg").selectedIndex=2 }
</script>
<select id="gg"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<input value="xiugai" type="button" onClick="ss()">
6)修改select的选中项
obj.selectedIndex=num //就是取中的索引值
<script>
function ss()
{ document.getElementById("gg").selectedIndex=2 }
</script>
<select id="gg"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<input value="xiugai" type="button" onClick="ss()">
7)得到所有选option的内容和value
obj.options[num].innerHTML //或者是value
<script>
function ss(num)
{ alert(document.getElementById("gg").options[num].innerHTML)
alert(document.getElementById("gg").options[num].value) }
</script>
<select id="gg"><option value="100">1</option><option value="200">2</option><option value="300">3</option></select>
<input value="xiugai" type="button" onClick="ss(document.getElementById('gg').selectedIndex)">
处于可编辑状态的option
<script>
function catchMP(e,obj){
e=e||event
var code =e.charCode||e.keyCode
obj.options[obj.selectedIndex].text = obj.options[obj.selectedIndex].text + String.fromCharCode(code);}
</script>
<select onkeypress="catchMP(event,this)">
<option>2</option>
<option>3</option>
</select>
没什么难的
fromCharCode()将Unicode码转换为对应的字符并返回为字符串
这个ff下没有中文的输入 唉 不兼容的东西感觉都没啥用呀,......
- Option操作呀。
- option操作
- jquery 操作 option
- select option 操作
- js 操作select option
- jQuery操作option
- jquery select option 操作
- jquery select option 操作
- jquery操作select option
- javascript option操作
- JS操作option
- select option 的操作
- js操作select option
- js操作select option
- jquery 操作option总结
- js 操作select option
- jquery删除操作option
- js操作select option
- KU-600变电站综合自动化系统
- (整理)日期转换参数,值得收藏
- 自动化抄表系统
- MySQL Order By Rand()效率
- GDI+ 支持的图片文件格式
- Option操作呀。
- .Net下使用System.Data.OracleClient出现“ORA-12154问题“TNS: 无法处理服务名”问题的解决
- 一个老IE写的文章。看看受益匪浅。
- 高效刪除重複記錄
- ATL3.0中的窗口类
- GDI
- 周杰伦大名远洋 出现在W3C规范里的第一人
- 连接webservice SocketException (0x274c)错误的解决方法
- 求助--在家不能上网,公司可以上网