浅析JQuery获取和设置Select选项的常用方法总结 - Web前端
作者:98wpeu发布时间:2026-07-10分类:网页前端技术浏览:3
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:
1>.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;
}
}
2>.$("#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:
1>. $("#cusChildTypeId").empty();
2>. $("#cusChildTypeId").get(0).options.length = 0;
相关推荐
- jQuery中获取Radio元素值的方法 - Web前端
- jquery异步跨域访问代码 - Web前端
- Jquery显示和隐藏元素或设为只读(含Ligerui的控件禁用,实例说明介绍) - Web前端
- 浏览器打开层自动缓慢展开收缩实例代码 - Web前端
- jquery点击页面任何区域实现鼠标焦点十字效果 - Web前端
- jQuery基本选择器选择元素使用介绍 - Web前端
- 关于JQuery($.load)事件的用法和分析 - Web前端
- jquery中文乱码的多种解决方法 - Web前端
- jquery移除button的inline onclick事件(已测试及兼容浏览器) - Web前端
- jQuery+css+html实现页面遮罩弹出框 - Web前端
- 网页前端技术排行
-
- 1分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 2jQuery编写widget的一些技巧分享 - Web前端
- 3【第六章】Foundation之按钮和下拉功能 - Web前端
- 4基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 5在Mac/PC上远程调试iPhone/iPad上的网页 - Web前端
- 6分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - Web前端
- 7jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 8[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 9javascript原生和jquery库实现iframe自适应高度和宽度 - Web前端
- 最近发表
-
- WordPress随机显示特色图片插件:Random Post Thumbnails
- KeePass实现Chrome浏览器自动填充密码方法一
- LNMP一键包nginx 301强制跳转到https教程
- KeePass实现Chrome浏览器自动填充密码方法二
- #建站# 免费的VPS管理软件Xshell8/Xftp8中文版下载
- 使用Xshell 8连接VPS教程_电脑登录vps的方法
- WordPress评论界面添加烟花????效果
- 不同浏览器书签同步方案:坚果云+Floccus_详细使用教程
- iOS端KeePassXC客户端APP:Strongbox Password Safe
- 给WordPress评论中的Gravatar头像图片添加ALT属性


