<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>