PHP
$ids = array_map('intval', json_decode($_GET['id']));
mysql_query("DELETE FROM topics WHERE id in (" . implode(',', $ids) . ")");
在 javascript 中(使用 jQuery)
function oki() {
var checked = $('.row:checked');
var ids = checked.map(function() { return $(this).val(); });
$.get('delete.php', {id: JSON.stringify(ids)}, function(response) {
checked.remove();
});
}
你的html是
Row with id 10: <input type="checkbox" class="row" value="10"/>
Row with id 20: <input type="checkbox" class="row" value="20"/>
Row with id 30: <input type="checkbox" class="row" value="30"/>
Row with id 40: <input type="checkbox" class="row" value="40"/>
<button onClick="oki();">Del</button>