【发布时间】:2012-02-15 14:42:52
【问题描述】:
使用数据表。问题是$('.checkbox') click 功能仅适用于数据表的第一页,其他任何地方都没有。请注意,$('#check_all') 适用于每一页。
JS 看起来是这样的:
function changeQt(){
if($('#quantity').is(':hidden'))
$('#quantity').fadeIn("slow");
$('#quantity').animate({
borderColor: "#00a9e0"
}, 'fast').text(totalqt).delay(400).animate({
borderColor: "#fff"
}, 'fast');
}
function doIt(obj) {
if ($(obj).is(":checked")) {
$(obj).closest("tr").not('#hdr').addClass("row_selected");
totalqt=totalqt + parseInt($(obj).closest("tr").find("#qt").text(), 10);
}
else {
$(obj).closest("tr").not('#hdr').removeClass("row_selected");
totalqt=totalqt - parseInt($(obj).closest("tr").find("#qt").text(), 10);
if(totalqt<0) totalqt=0;
}
}
function checkAllCheckboxes(isChecked) {
if(isChecked ){
totalqt=0;
}
$('.checkbox').each(function(){
$(this).prop('checked', isChecked);
doIt(this);
});
changeQt();
}
$(document).delegate('td.item_id', 'click', function(e){
e.stopPropagation();
});
$(document).delegate('#list > tbody > tr', 'click', function(){
window.open($(this).attr("url"));
});
$(document).ready(function() {
$("input:submit, input:reset").button();
$.datepicker.regional[""].dateFormat = 'dd.mm.yy';
$.datepicker.setDefaults($.datepicker.regional['']);
$('select[name=list_length]').change(function(){
if ($('#check_all').is(':checked'))
$('#check_all').click();
});
var oTable= $('#list').dataTable( {
"bJQueryUI": true,
"iDisplayLength": 25,
"aaSorting": [],
"aoColumns": [
{
"bSortable": false
},
null, null, null,null,null, null, null
]
} ).columnFilter({
sPlaceHolder: "head:before",
aoColumns: [ null, null, null,null,null, null, null,
{
type: "date-range"
}
]
});
$('.checkbox').click(function(e) {
e.stopPropagation();
doIt(this);
changeQt()
});
$('select[name=list_length]').change(function(){
if($('#check_all').is(':checked')){
$('#check_all').prop('checked', false);
checkAllCheckboxes(false);
}
});
$('#check_all').click(function(){
checkAllCheckboxes(this.checked);
});
});
这是该表中的 1 行:
<tr url="?page=item&id=1411">
<td class="item_id"><input type="checkbox" name="checkbox[]" method="post" value="1411" class="checkbox"/> 1411</td>
<td> 9814</td>
<td style="text-align:center">BK</td>
<td style="text-align:center">36</td>
<td style="text-align:center" id="qt">1</td>
<td style="text-align:center">15</td>
<td style="text-align:center">12</td>
<td>15.02.2012</td>
</tr>
如果有人想查看实际页面,请加入讨论:Here。
【问题讨论】:
标签: javascript jquery checkbox click datatables