热门:网页模板.net视频教程JQueryMVCjsonExtJs源码示例三级联动JQuery菜单
您现在的位置:.Net中文社区>> AJAX编程>>正文内容

jQuery-对Radio/CheckBox的操作集合

发布时间:2010年04月14日点击数: 佚名

jQuery获取Radio选择的Value值代码:

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

jQuery获取CheckBox选择的Value值

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

上面的这些操作,其实就是jQuery选择器的使用,希望大家对jQuery选择器方面的知识要掌握扎实。

本站热点业务

更多模板/案例展示

关于我们 | 联系我们 | 团队日志 | 网站地图 | 网站合作