笔记 js操作select option的常用代码
来源:互联网 发布:如何查看淘宝流量来源 编辑:程序博客网 时间:2024/06/08 08:49
1.获取select 选中的 text:
$("#cusChildTypeId").find("option:selected").text();
$("#cusChildTypeId option:selected").text()
2.获取select选中的 value:
$("#ddlRegType ").val();
3.获取select选中的索引:
$("#ddlRegType ").get(0).selectedIndex;
4.得到select项的个数
$("#cusChildTypeId").get(0).options.length
5.设置select 选中的索引:
$("#cusChildTypeId").get(0).selectedIndex=index;//index为索引值
6.设置select 选中的value:
$("#cusChildTypeId").attr("value","Normal");
$("#cusChildTypeId").val("Normal");
$("#cusChildTypeId").get(0).value = "Normal";
7.设置select 选中的text:
var count=$("#cusChildTypeId").get(0).options.length;
for(var i=0;i<count;i++)
{
if($("#cusChildTypeId").get(0).options.text == text)
{
$("#cusChildTypeId").get(0).options.selected = true;
break;
}
}
$("#cusChildTypeId").val(text);
$("#cusChildTypeId").change();
8.向select中添加一项,显示内容为text,值为value
$("#cusChildTypeId").get(0).options.add(new Option(text,value));
9.删除select中值为value的项
var count = $("#cusChildTypeId").size();
for(var i=0;i<count;i++)
{
if($("#cusChildTypeId").get(0).options[i].value == value)
{
$("#cusChildTypeId").get(0).remove(i);
break;
}
}
10.清空 Select:
$("#cusChildTypeId").empty();
$("#cusChildTypeId").get(0).options.length = 0;
- 笔记 js操作select option的常用代码
- js 操作select和option常用代码整理
- js 操作select option
- js操作select option
- js操作select option
- js 操作select option
- js操作select option
- js操作select option
- js操作select option
- js select的option的操作
- JS操作select控件的option
- select option 的操作
- select option的操作
- js 操作select和option
- js 操作select和option
- js 操作select和option
- js 操作select和option
- js 操作select和option
- scikit-learn中评估分类器性能的度量,像混淆矩阵、ROC、AUC等
- LeakCanary工具使用
- 1.9版本 .toggle()方法删除
- ElasticSearch优化系列一:集群节点规划
- GPU CUDA 杭州宣讲会
- 笔记 js操作select option的常用代码
- [2017-11-07]相应头 X-ReqId
- java简介
- 更新版 | GPU CUDA 进阶课程
- Android全屏浏览图片
- 最终章 | TensorFlow战Kaggle“手写识别达成99%准确率
- 面向对象进阶
- 绎维突破‘复杂业务建模技术’,获红杉中国3000万投资打造一站式商业分析平台
- 决策树会有哪些特性?