我有以下html代码的数据行是动态生成使用php
<tr>
<td><input type='checkbox' name='post[]' value="1"></td>
<td>21-Apr-2014</td>
<td>TEST</td>
<td>merchant.inloc8.com</td>
<td>coupon</td>
<td>mmmq.com/id/rt7WLskQq2lLlO2kTN</td>
<td>abc.com/response.php (default)</td>
<!--<td align='center' width='30'><a data-toggle='modal' href='#' ><i class='icon-remove text-danger'></i></a></td> -->
</tr>
<tr>
<td><input type='checkbox' name='post[]' value="2"></td>
<td>21-Apr-2014</td>
<td>say nw</td>
<td>abcdefg.com</td>
<td>abc</td>
<td>mmmq.com/id/lbruxjFl6PitP25vTN</td>
<td>abc.com/response.php (default)</td>
<!--<td align='center' width='30'><a data-toggle='modal' href='#' ><i class='icon-remove text-danger'></i></a></td> -->
</tr>
当选中一个复选框时,我想识别该行并在后端删除该行。我认为这可以用ajax来完成。但我不知道。请帮助
看这个例子
复选框。
<input type="checkbox" value="1" name="letter[]" />
<input type="checkbox" value="2" name="letter[]" />
<input type="checkbox" value="3" name="letter[]" />
<input type="button" id="btn_" value="submit" />
当按钮被点击时,你可以将选中的复选框的值作为一个数组传递给ajax调用,
$("#btn_").on('click', function () {
arr=[];
var arr = $("input[name='letter[]']:checked").map(function() {
return this.value;
}).get();
$.ajax({
type: "POST",
data: {arr:arr},
url: "action.php",
success: function(msg){
alert("success");
}
});
});
您将在action.php中获得值并删除那里的行。您可以将alert("success");
更改为您想要获得的回调。
序列化表单数据,传递给控制器,删除条目。此处为完整提纲
看,我只给你逻辑。如果我给你代码,你什么也学不到。
那么,将复选框的值设置为Table的$id,一旦单击submit,选中所有被选中的$id,并运行一个循环,通过查询删除$id