<?= Html::button('全选', ['class' => "btn margin select-check-all"])?>
<?= Html::button('全不选', ['class' => "btn margin dont-check-all"])?>
<?= Html::button('下架', ['class' => "btn btn-primary margin unshelve-check"])?>
<?php
$this->registerJs( <<< JS
$('.select-check-all').click(function(){
$("table input[type=checkbox]").prop("checked",true);
});
$('.dont-check-all').click(function(){
$("table input[type=checkbox]").prop('checked',false);
});
$(".unshelve-check").on('click', function(){
var ids = [];
var flag = 0;
$('input[type=checkbox]:checked').each(function() {
if ($(this).attr('name') != 'task_selection_all') {
ids[flag] = $(this).attr('value');
flag += 1;
}
});
if(flag == 0) {
alert('请至少选择一项!');
return false;
}
var action = "unshelve-check?ids=" + ids;
$.ajax({
url: action,
success: function (data) {
console.log('success');
$.pjax.reload({container:"#article_index", timeout:5000});
},
error: function (e) {
console.log('error');
alert('失败');
}
});
});
JS
);
?>
关于checkbox的全选,全不选以及提交数据
最新推荐文章于 2023-11-06 08:00:00 发布