我是php新手。我希望通过选中复选框删除多行,但在我的代码中,只有选中所有复选框才会删除它。如果我从中选择一个是删除...可以帮助我解决这个问题
var is_activate = true; // we will track which input button was clicked :)
jQuery(function($) {
$("#form input#check_all").change(function() {
var inputs = $("#form input[type='checkbox']");
if ( $(this).is(":checked") ) {
inputs.prop( "checked", true );
// inputs.attr( "checked", true ); // if its not working
}
else {
inputs.removeAttr( "checked" );
}
});
// Track clicked button
$("#form input[type=submit]").on("click",function(e) {
is_activate = ( $(this).hasClass("activate_btn") ) ? true : false;
});
$("#form").submit(function(e) {
e.preventDefault();
var string = ( is_activate ) ? 'activate' : 'delete';
var data = $(this).serialize();
var checked = $(this).find("input[name='data[]']:checked").length;
if ( checked == 0 ) {
alert( "Please select a record(s) to "+string+"." );
return false;
}
var text = "Are you sure you want to "+string+" these Notices"+( ( checked == 1 ) ? "?" : "s?" );
if ( confirm( text ) ) {
$.ajax({
url: 'resources/ajax/'+( ( is_activate ) ? 'ajax_activate_comment.php' : 'noticeView.php?delete=$w' ),
type: 'post',
data: data,
success: function( data ) {
}
});
}
});
});
我的复选框
echo "<input name='data[]' type='checkbox' id='data' value=''/> ";
答案 0 :(得分:0)
在你的php中
$data = $_POST['data'];
foreach($data as $d)
{
//delete query by $d as id
}