我试图写一个脚本与jQuery复选框id被选中的帖子(php删除脚本)。
我有这样的东西
<form>
<input type="checkbox" name="id" id="id" value='1'>
<input type="checkbox" name="id" id="id" value='2'>
<input type="checkbox" name="id" id="id" value='3'>
<input type="button" name="DELETE" id="DELETE">
</form>
所以我想张贴这些值(id)到一个php文件delete.php,我怎么能做到这一点?
HTML
<form>
<input type="checkbox" name="id" value='1'>
<input type="checkbox" name="id" value='2'>
<input type="checkbox" name="id" value='3'>
<input type="button" name="DELETE" id="DELETE">
</form>
JQUERY
<script>
$(document).ready(function(){
$("#delete").click(function(){
var data = $('input:checkbox:checked').map(function(){
return this.value;
}).get();
var dataString = "imgList="+ data;
$.post('delete.php',dataString,function(theResponse){
//// Check theResponse
});
});
});
</script>
PHP
$imgList = $_REQUEST['imgList'];
$i = 0;
$token = strtok($imgList, ",");
$imgArray = array();
while ($token != false){
$imgArray[$i] = (string)$token;
$token = strtok(",");
$i++;
}
我假设您希望通过使用jQuery ajax调用post到php
来实现这一点