打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
JQuery中对Radio和CheckBox的对比使用

一. jQuery-对Radio/CheckBox的操作集合

 

  1. jQuery获取Radio选择的Value值  
  2.   
  3. $("input[name='radio_name'][checked]").val(); //选择被选中Radio的Value值   
  4.  $("#text_id").focus(function(){//code...}); //事件 当对象text_id获取焦点时触发   
  5.  $("#text_id").blur(function(){//code...}); //事件 当对象text_id失去焦点时触发   
  6.  $("#text_id").select(); //使文本框的Vlaue值成选中状态   
  7. $("input[name='radio_name'][value='要选中Radio的Value值'").  
  8. attr("checked",true); //根据Value值设置Radio为选中状态   
  9.   
  10. jQuery获取CheckBox选择的Value值  
  11.   
  12.  $("input[name='check']:checked");  
  13.   
  14.   
  15. $("input[name='checkbox_name'][checked]"); //选择被选中CheckBox元素的集合 如果你想得到   
  16. Value值你需要遍历这个集合  
  17. $($("input[name='checkbox_name'][checked]")).  
  18. each(function(){arrChk+=this.value + ',';});//遍历被选中CheckBox元素的集合 得到Value值   
  19. $("#checkbox_id").attr("checked"); //获取一个CheckBox的状态(有没有被选中,返回true/false)   
  20. $("#checkbox_id").attr("checked",true); //设置一个CheckBox的状态为选中(checked=true)   
  21. $("#checkbox_id").attr("checked",false); //设置一个CheckBox的状态为不选中(checked=false)   
  22. $("input[name='checkbox_name']").attr  
  23. ("checked",$("#checkbox_id").attr("checked"));//根据3,4,5条,你可以分析分析这句代码的意思    
  24. $("#text_id").val().split(","); //将Text的Value值以','分隔 返回一个数组  

 

 

二. jQuery实现CheckBox全选、全不选

 

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head runat="server">  
  4.     <title>Index</title>  
  5.   
  6.      <mce:script src="/Scripts/jquery-1.4.1.js" mce_src="Scripts/jquery-1.4.1.js" type="text/javascript"></mce:script>    <mce:script type="text/javascript"><!--  
  7.         $(function() {  
  8.             $("#CheckAll").click(function() {  
  9.                 var flag = $(this).attr("checked");  
  10.                 $("[name=subBox]:checkbox").each(function() {  
  11.                     $(this).attr("checked", flag);  
  12.                 })  
  13.             })  
  14.         })  
  15.       
  16. // --></mce:script>   
  17.   
  18. </head>  
  19. <body>  
  20.     <div>  
  21.         <input id="CheckAll" type="checkbox" />  
  22.         <input name="subBox" type="checkbox" />  
  23.         <input name="subBox" type="checkbox" />  
  24.         <input name="subBox" type="checkbox" />  
  25.         <input name="subBox" type="checkbox" />  
  26.     </div>  
  27. </body>  
  28. </html>  
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
jquery判断一组checkbox中是否至少选中了一个
jquery的checkbox,radio,select等方法总结
jquery判断单选按钮是否选中
jQuery对select操作小结 - 鬼鬼DH - 博客园
JQUERY获取text,areatext,radio,checkbox,select值
Jquery主要控件的取值、赋值,包括textbox,button,lable,radio,checkbox,selected
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服