码迷,mamicode.com
首页 > Web开发 > 详细

jQuery判断checkbox是否选中的3种方法

时间:2017-05-24 13:42:52      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:attr   check   class   his   input   something   war   判断   选中   

方法一:
if ($("#checkbox-id").get(0).checked) {
    // do something
}

方法二:
if($(‘#checkbox-id‘).is(‘:checked‘)) {
    // do something
}

方法三:
if ($(‘#checkbox-id‘).attr(‘checked‘)) {
    // do something
}
在jQuery1.6版本之后,取复选框有没有被选中,要用prop
if($(‘#checkbox-id‘).prop(‘checked‘))
{
  //do something
}
 

 function checkInfo(){
  $("input[name=‘org3.otherValues‘]").each(
   function(){
   if($(this).get(0).checked){
   return true;
    }
   });
  var org3_ids=$("#org3_ids").val();
  if(org3_ids!=‘‘){
   return true;
  }
  
  alertMsg.warn("请选择接收人!");
  return false;
 }

  

jQuery判断checkbox是否选中的3种方法

标签:attr   check   class   his   input   something   war   判断   选中   

原文地址:http://www.cnblogs.com/achengmu/p/6898416.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!