jquery 操作select,checkbox,radio (整理)
在工作中经经常使用到select,checkbox,radio,今天有点空暇就整理一下,免得以后用的时候还要又一次找。
操作select下拉框
—— 获取值或选中项:
1, $("#select_id").change(function(){//code...}); //为Select加入事件。当选择当中一项时触发
2。var checkValue=$("#select_id").val(); //获取Select选择的Value
3,var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的Text
4。$("#columnName").find("option:selected").attr("price");//获取select选择项中的price属性的值
5,$("#columnName option[value='3']").attr("price");//获取value值为3的选择项的price的属性的值
6,var checkIndex=$("#select_id ").get(0).selectedIndex; //获取Select选择的索引值
7,var maxIndex=$("#select_id option:last").attr("index"); //获取Select最大的索引值
8,$("#select_id option[value='3']").attr("selected",true);//依据value值为3的项选中
9,$("#select_id ").val(‘4’); // 设置Value值为4的项选中
10,$("#select_id ").get(0).selectedIndex=2; //设置Select索引值为2的项选中
11。$("#select_id option[text='jQuery']").attr("selected", true); //设置Select的Text值为jQuery的项选中
—— 加入/删除Select的Option项:
1,$("#select_id").append("<option value='Value'>Text</option>"); //为Select追加一个Option(下拉项)
2,$("#select_id").prepend("<option value='0'>请选择</option>"); //为Select插入一个Option(第一个位置)
3,$("#select_id option:last").remove(); //删除Select中索引值最大Option(最后一个)
4。$("#select_id option[index='0']").remove(); //删除Select中索引值为0的Option(第一个)
5。$("#select_id option[value='3']").remove(); //删除Select中Value='3'的Option
6,$("#select_id option[text='4']").remove(); //删除Select中Text='4'的Option
7。$("#select_id").empty(); //清空Select中的Option
操作checkbox多选框
1,//因为复选框一般选中的是多个,所以能够循环输出选择项的值
var payFlightSts='';
$('input[name="payFlightSts_'+currCount+'"]:checked').each(function(){
payFlightSts+=$(this).val()+‘,’;
});
2,//获取未选中的checkbox的值:
$("input[name='box']").each(function(){
if ($(this).attr('checked') ==false) {
alert($(this).val());
}
});
3,//全选
$("#btn1").click(function(){
$("input[name='box']").attr("checked","true");
})
4,//取消全选
$("#btn2").click(function(){
$("input[name='box']").removeAttr("checked");
})
5,//返选
$("#btn4").click(function(){
$("input[name='checkbox']").each(function(){
if($(this).attr("checked")) {
$(this).removeAttr("checked");
} else {
$(this).attr("checked","true");
}
})
})
操作radio单选框
1,$('input[name="testradio"]:checked').val();//获取选择的value值
2。//遍历name为testraio的全部选择项
$('input[name="testradio"]').each(function(){
alert(this.value);});
3,设置选中与否(rdo1为选中项的id)
$("#rdo1").attr("checked","checked");
$("#rdo1").removeAttr("checked");
jquery 操作select,checkbox,radio (整理)的更多相关文章
- JQuery操作select checkbox radio总结
JQuery是一个非常强大的工具,所以我必须找到它最方便的方法,嘻嘻 Select CRUD: Select搜: 1.val值: $("#selectid").val(); ...
- Jquery操作select,radio,input,p之类
select的操作 变化后触发操作 $("#txtaddprojecturl").change(function(){ $("#addprojectname") ...
- jQuery设置 select、radio、checkbox 默认选中的值
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JQuery操作select下拉框
JQuery操作select下拉框 获取Select选择的Text和Value $("#select_id").change(function(){//code...}); //为 ...
- Jquery操作select,左右移动,双击移动 取到所有option的值
$(function () { function MoveItem(fromId, toId) { $("#" + fromId + " option:selected& ...
- ThinkPHP第二十六天(JQuery操作select,SESSION和COOKIE)
1.JQuery操作select,假设<select id="my"> A:双击选项<option>事件,应该是select的dbclick事件. B:获得 ...
- jquery操作select下拉框的各种方法,获取选中项的值或文本,根据指定的值或文本选中select的option项等
简介jquery里对select进行各种操作的方法,如联动.取值.根据值或文本来选中指定的select下拉框指定的option选项,读取select选中项的值和文本等. 这一章,站长总结一下jquer ...
- js与jQuery操作select大全
Js操作Select是很常见的,也是比较实用的,每一次操作select的时候,总是要出来翻一下资料,不如自己总结一下,以后就翻这里了. 一.js操作select部分 判断select选项中 是否存在V ...
- Jquery 操作 Select 详解
jQuery是如何控制和操作select的.先看下面的代码 比如<select class="selector"></select> 1.设置value为p ...
随机推荐
- linux针对TCP和 UDP的调优
- Nginx优化_定义对静态页面的缓存时间
修改Nginx配置文件,定义对静态页面的缓存时间 proxy ]# vim /usr/local/nginx/conf/nginx.conf server { listen 80; server_na ...
- Oracle Set操作
并集合 union/uinon all union 会去重,uinon all 不去重 交集 intersect 差集 minus
- 客户端模拟线程线程池发送100个文件给socket
1.线程池模拟发送100个线程发送 2.每个线程启动一个socket发送文件 3.线程池最大并发几个
- 理解uboot过程中的优秀博客
To_run_away的博客 https://blog.csdn.net/qq_16777851/column/info/28098/5 加了微信好友,公众号也有文章. Camus https://c ...
- 阿里云弹性裸金属服务器-神龙架构(X-Dragon)揭秘
在5月16日的飞天技术会新品直播中,特别邀请了业界知名大咖狒哥以及阿里云虚拟化资深专家旭卿作为现场直播的嘉宾.本次直播主要从产品背景到“X-Dragon架构”,从硬件设备到软件应用来深度的剖析“X-D ...
- CABasicAnimation来做心跳动画
CABasicAnimation *anim = [CABasicAnimation animation]; anim.keyPath = @"transform.scale"; ...
- elasticsearch-head插件添加安全认证
elasticsearch-head是集群管理.数据可视化.增删查改.查询语句可视化工具;它可以对数据进行增删查改,对于数据安全来说是有风险的,因此在生产环境中尽量少用,使用该插件至少要限制ip地址或 ...
- 批量搞机(二):分布式ELK平台、Elasticsearch介绍、Elasticsearch集群安装、ES 插件的安装与使用
一.分布式ELK平台 ELK的介绍: ELK 是什么? Sina.饿了么.携程.华为.美团.freewheel.畅捷通 .新浪微博.大讲台.魅族.IBM...... 这些公司都在使用 ELK!ELK! ...
- brew安装指定版本的软件
原文:https://www.jianshu.com/p/aadb54eac0a8 在mac中使用 brew install 安装的软件默认都是最新版本的.有时候我们需要旧版本(指定版本)的时候,应该 ...