select中option解析
来源:互联网 发布:计算机二级vb 编辑:程序博客网 时间:2024/05/20 18:54
select动态添option:
var sel=document.getElementById(selectId); //获取select
var newOpt=document.createElement("OPTON");
newOpt.setAttribute("value",optValue); //option的value值
newOpt.innerHTML=optText; //option中文本值
sel.appendChild(newOpt); //将option加入到sel中
获得指定位置的option
var sel=document.getElementById(selectId);
var index=position; //option中未知索引,0,1,2,,
var theOpt=sel.options[index]; //获得该option
或者用jquery
var theOpt=jQuery("#selectId option[index='position']");
表示获取index为position的option
var theOpt=jQuery("#selectId option[value='value']");
表示根据value值来获取指定的option
注意:动态添加option的select不能通过index来获取option,
可以用value等其他属性来获取。
var sel=document.getElementById(selectId); //获取select
var newOpt=document.createElement("OPTON");
newOpt.setAttribute("value",optValue); //option的value值
newOpt.innerHTML=optText; //option中文本值
sel.appendChild(newOpt); //将option加入到sel中
获得指定位置的option
var sel=document.getElementById(selectId);
var index=position; //option中未知索引,0,1,2,,
var theOpt=sel.options[index]; //获得该option
或者用jquery
var theOpt=jQuery("#selectId option[index='position']");
表示获取index为position的option
var theOpt=jQuery("#selectId option[value='value']");
表示根据value值来获取指定的option
注意:动态添加option的select不能通过index来获取option,
可以用value等其他属性来获取。
0 0
- select中option解析
- 删除select中所有option
- 删除select中所有option
- select中添加、删除option
- 从input中添加select option
- select中添加、修改、删除option元素
- select中添加、修改、删除option元素
- javascript操作Select标记中option集合
- 获取select中option的value值
- firefox 中对 select option 操作
- 获取select中option中的文本节点
- select中不可选择的option
- Javascript向Select中添加option(备忘)
- Jquery select option在html中使用
- Javascript清除Select中Option值
- select中添加、修改、删除option元素
- 去除select中重复的option
- 动态改变select中option的次序
- 【Python】 sorted函数
- 为什么析构函数是虚函数
- [C/C++]C++常用的基础小结
- MySQL 性能优化的最佳 20+ 条经验
- caffe入门----Layer
- select中option解析
- float浮动
- mysql的join操作
- 题目1370:数组中出现次数超过一半的数字
- 模拟实现栈
- java-值传递-基本类型/对象类型
- mysql的show操作
- 查找
- Android screen monitor