Jquery中文网 www.jquerycn.cn
Jquery中文网 >  jQuery  >  jquery 教程  >  正文 jQuery获取Radio,CheckBox选择的Value值(示例代码)

jQuery获取Radio,CheckBox选择的Value值(示例代码)

发布时间:2014-05-26   编辑:www.jquerycn.cn
这篇文章主要是对jQuery获取Radio,CheckBox选择的Value值进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助

$("input[name='radio_name'][checked]").val(); //选择被选中Radio的Value值
$("#text_id").focus(function(){//code...}); //事件 当对象text_id获取焦点时触发
$("#text_id").blur(function(){//code...}); //事件 当对象text_id失去焦点时触发
$("#text_id").select(); //使文本框的Vlaue值成选中状态
$("input[name='radio_name'][value='要选中Radio的Value值'").
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(","); //将Text的Value值以','分隔 返回一个数组

您可能感兴趣的文章:
jQuery获取Radio,CheckBox选择的Value值(示例代码)
jquery 获取表单元素里面的值示例代码
JQuery操作三大控件(下拉,单选,复选)的方法
Jquery操作radio,checkbox,select表单实例
jquery操作radio、checkbox、select的实例代码
jQuery获取Select中Text与Value值
php获取checkbox值
Jquery获取Select下拉框中Text与Value的方法详解
jquery获取form表单元素值的实例
jquery操作select实例

关键词: jQuery  Radio  CheckBox   
[关闭]