<input type="checkbox" id="chk_all">
<input type="checkbox" name="ids[]" value="<?= $val['news_partner_id'] ?>">
<input type="button" name="no" value="合作">
<input type="button" name="stop" value="暫停合作">
<input type="button" name="off" value="關閉">
<script>
// 全選 & 反選
$("#chk_all").on('click', function () {
$("input[name='ids[]']").attr("checked", $(this).attr("checked"));
$("input[name='ids[]']").prop("checked", $(this).prop("checked"));
});
//啟用合作
$("input[name='no']").on('click', function () {
if ($("input[name='ids[]']").is(':checked')) {
// 擷取所有選中的項并把選中項的文本組成一個字元串
var str = '';
$($("input[name='ids[]']:checked")).each(function () {
str += $(this).val() + ',';
});
if (confirm("确認啟用合作?")) {
$.ajax({
type: 'POST',
url: 'save-status',
data: {'ids': str, 'status': 1},
success: function (msg) {
if (msg == 1) {
window.location.reload();
} else {
alert('啟用合作失敗');
}
},
});
}
} else {
alert('未選中資料');
}
});
</script>