2014-10-17 181 views
-4

我用JQuery时,我试图检查所有功能,然后在那里,因为这个JS没有显示所有选中的字段,但当我删除那个JS然后滑块受影响。所以请尝试解决我的问题,我也没有使用冲突功能,但它不工作。“检查所有”不检查复选框

 <script type="text/javascript"> 
     jQuery.noConflict() 
     jQuery.ready(function() { 
      jQuery("#selectall").click(function() { 
       $('.case').attr('checked', this.checked); 
      }); // prototype 
     }); 
    </script> 

<div class="accordion-heading"> 
    <input type="checkbox" id="selectall" name="sample" class="selectall" /> 
    <div style="float:left; "> <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion1" href="#collapse_1" /> Admin Module 
    </div> 
    </a> 
</div> 
<div id="collapse_1" class="accordion-body collapse in"> 
    <div class="accordion-inner" id="checkboxlist"> 
     <table class="table table-bordered table-hover" id="test" align="center" style="width:100%"> 
      <tr> 

       <th width="450"><strong>Form Name</strong> 
       </th> 
       <th width="150"><strong>select</strong> 
       </th> 
       <th width="150"><strong>Edit</strong> </th> 
       <th width="150"><strong>Delete</strong> 
       </th> 
       <th width="150"><strong>View</strong> 
       </th> 
      </tr> 
      <tr> 
       <td style="padding-left:20%">Authentication</td> 
       <td style="padding-left:8%"> 
        <input type="checkbox" id="case1" name="emailid[]" value="" class="case" /> </td> 
       <td style="padding-left:8%"> 
        <input type="checkbox" id="case1" name="emailid[]" value="" class="case" /> 
       </td> 
       <td style="padding-left:8%"> 
        <input type="checkbox" id="case1" name="emailid[]" value="" class="case" /> </td> 
       <td style="padding-left:8%"> 
        <input type="checkbox" id="case1" name="emailid[]" value="" class="case" /> 
       </td> 
      </tr> 
+4

什么是你的问题? – 2014-10-17 08:08:04

+0

冲突java脚本 – Mahesh 2014-10-17 08:08:57

+0

可能的重复[如何使用jQuery检查复选框?](http://stackoverflow.com/questions/426258/how-do-i-check-a-checkbox-with-jquery) – OIS 2014-10-17 08:10:34

回答

3

你的simpy做错了,只有当前文档有一个现成的处理程序,你应该使用prop设置属性,并听取了change事件时,它的一个复选框。

jQuery(function($) { 
    $("#selectall").on('change', function() { 
     $('.case').prop('checked', this.checked); 
    }); 
}); 

记住你的脚本

FIDDLE

+0

谢谢你但它不工作。 – Mahesh 2014-10-17 08:17:05

+0

你尝试了小提琴,似乎为我工作得很好吗? – adeneo 2014-10-17 08:19:45

+0

你能告诉我我在哪里使用变化吗? – Mahesh 2014-10-17 08:20:40

0

如果我理解正确的之前,实际上包括jQuery的,这是你应该如何处理jQuery.noConflict():

<script type="text/javascript"> 
jQuery.noConflict(); 
// Here, $ is a reference to whatever it was assign (if I understand correctly, it is prototypeJS) 
(function($) { 
    // Here, $ is a reference to jQuery 
    $(function($) { 
     $("#selectall").click(function() { 
      $('.case').attr('checked', this.checked); 
     }); // jQuery 
    }); 
})(jQuery); 
// Here, $ is a reference to whatever it was assign (if I understand correctly, it is prototypeJS) 
</script>