2013-04-10 68 views
-1

我一直在使用引導表來使用kendo數據源從數據庫中獲取數據。所以爲了讓它更具互動性,我使用了複選框來同時執行動作。選擇所有複選框不起作用

我想用一個複選框刪除所有條目。我已閱讀關於使用jQuery單個複選框刪除條目。但問題是我在表中只有一個複選框,並且所有條目都使用kendo數據源獲取。

如果我製造混亂,然後看到這裏 -

<script id="template" type="text/x-kendo-template"> 
    <tr> 
     <td> 
      <input type="checkbox" class="done" data-id="#= CID #" ></input> 

     </td></tr> 
</script> 

<table> 
<tr> 
<th style="width:10%;"> 
         <input type="checkbox" /> 
        </th> 
</tr> 
</table> 

現在使用的劍道數據源,我只有一個複選框列。

,所以我做這個 -

<script type="text/javascript"> 
     $('.done').click(function (event) { 
      if (this.checked) { 
       // Iterate each checkbox 
       $(':checkbox').each(function() { 
        this.checked = true; 
       }); 
      } 
     }); 

    </script> 

而且還是沒有結果。幫幫我!

+2

你的HTML代碼似乎馬車!腳本標籤中還有一個額外的單一代碼和html代碼。 – 2013-04-10 10:13:55

回答

0

嘗試包內$(document).ready(function(){});$(function(){}); jQuery代碼讓它看到整個DOM:

$(document).ready(function() { 
    $('.done').click(function (event) { 
     if (this.checked) { 
      // Iterate each checkbox 
      $(':checkbox').each(function() { 
       this.checked = true; 
      }); 
     } 
    }); 
}); 

而且,你的HTML被包裹在script標籤內,外移動,並刪除冗餘'以及在input標籤不需要關閉</input>標籤:

<tr> 
    <td> 
     <input type="checkbox" class="done" data-id="#= CID #" /> 
    </td> 
</tr> 
0
<script type="text/javascript"> 
$(document).ready(function(){ 
    $('.done').click(function (event) { 
     if ($(this).attr('checked')) { 
      $('input:checkbox:not(".done")').each(function() { 
       $(this).attr('checked', 'checked'); 
      }); 
      } 
     }); 
}); 
</script> 

試試這個。它可以工作

0

試試這個:

$(function() {  
    $('.done').on('click', function(){ 
       // i comment this condition if you want selectall for checked or unchecked 
       //if ($(this).is(':checked')){ 
         $(':checkbox').prop('checked', this.checked); 
       //} 
    }); 
}); 
+0

你的代碼似乎很好,但這對我來說並不適用,因爲我只有一個盒子,並且有數據源,它會創建一個複選框列表。 – Manoj 2013-04-10 10:30:45

+0

@Manoz我認爲你需要在你的kendo腳本之後執行這個jQuery函數。 – 2013-04-10 10:34:19

0

就試試這個:

腳本

$(document).ready(function(){ 
    $('.done').click(function (event) { 
     $('.chkbxq').each(function() { 
     $(this).attr('checked', flag); 
     }); 
    }); 
}); 

HTML:

<table> 
    <tr> 
    <th style="width:10%;"> 
     <input type="checkbox" class="chkbxq" /> 
    </th> 
    </tr> 
</table>