jQuery获取Radio,CheckBox选择的Value值

本文转自:http://blog.sina.com.cn/s/blog_66b46f5f0100qxfh.html


jQuery获取Radio选择的Value


$("input[name='radio_name']:checked").val();//选择被选中RadioValue
$("#text_id").focus(function(){//code...}); //事件 当对象text_id获取焦点时触发
$("#text_id").blur(function(){//code...}); //事件 当对象text_id失去焦点时触发
$("#text_id").select();//使文本框的Vlaue值成选中状态
$("input[name='radio_name'][value='要选中RadioValue'").attr("checked",true);//根据Value值设置Radio为选中状态

 

 

 

jQuery获取CheckBox选择的Value

 

$("input[name='checkbox_name'][checked]");//选择被选中CheckBox元素的集合 如果你想得到
Value
值你需要遍历这个集合
$($("input[name='checkbox_name'][checked]")).
each(
function(){arrChk+=this.value + ',';});//遍历被选中CheckBox元素的集合 得到Value
$("#checkbox_id").attr("checked");//获取一个CheckBox的状态(有没有被选中,返回true/false)
$("#checkbox_id").attr("checked",true);//设置一个CheckBox的状态为选中(checked=true)
$("#checkbox_id").attr("checked",false);//设置一个CheckBox的状态为不选中(checked=false)
$("input[name='checkbox_name']").attr
("checked",$("#checkbox_id").attr("checked"));
//根据3,4,5条,你可以分析分析这句代码的意思
$("#text_id").val().split(",");//TextValue值以','分隔 返回一个数组

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值