2014-10-17 190 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>