這是一個帶有嵌套gridviews的asp.net webforms頁面。數組中的複選框上的Jquery.change
我有一個表,動態地添加每個行下的多個「詳細信息」表。 細節表在標題中有一個「全選」複選框,在其下面的每一行都有一個複選框。
我試圖在選中標題級複選框時選擇所有子行復選框。
<div>
<table class="details">
<tbody>
<tr style="white-space:nowrap;">
<th scope="col">
<span class="ckbSelectAll">
<input type="checkbox" />
</span>
</th>
<th scope="col">number</th>
<th scope="col">Status</th>
</tr>
<tr>
<td>
<span class="ckbResults">
<input type="checkbox" />
</span>
</td>
<td>121223</td>
<td>Open</td>
</tr>
</tbody>
</table>
我能找到的所有頭級別的複選框(ckbSelectAll)通過尋找類和尋找的複選框。我看到我有一個包含所有標題級別複選框的數組,但.change似乎沒有觸發任何一個。
$.each($('.ckbSelectAll input[type="checkbox"]'),function (index, value) {
$(value).change(function() {
alert('checked');
}) });
我想這可能是.change,我已經用。對(「改變」,()的函數和。對(「點擊」,()的函數嘗試,但就是無法獲得點擊或改變觸發警報
'$ .each()'是爲數組或對象設計的。建議使用'.each()'。像這樣:'$('.ckbSelectAll input [type =「checkbox」]')。each(function(ind,el){$(el).change(function(){alert(「checked」);}); });' – Twisty