标签:asc check elements 选中 oca info ima var .ajax
最重要的是要在其中给value赋值为当前id,通过name查询到id值
JS代码:
<script type="text/javascript">
function shanchu() {
var obj = document.getElementsByName(‘GroupAll‘);
var duoxuan = ‘‘;
for (var i = 0; i < obj.length; i++) {
if (obj[i].checked) {
duoxuan = obj[i].value + ‘,‘;//如果选中,将value添加到变量duoxuan中
// alert(duoxuan);
}
}
if (duoxuan.length < 1) {
alert(‘请至少选择一项!‘);
return 0;
} else {
if (!(confirm(‘是否确定删除?‘))) {
return false;
}
$.ajax({
url: ‘{:U("Home/Stock/shanchu")}‘,
type: ‘post‘,
//dataType: ‘text‘,
data: {"duoxuan": duoxuan},
success: function (data) {
if (data == "Y") {
alert("删除成功!");
window.location.href = "/Home/Stock/index";
}
},
error: function () {
alert("删除失败!");
}
});
}
后台代码:
public function shanchu() {
$id = $_POST[‘duoxuan‘];
$whe[‘id‘] = array(‘in‘, $id);
$mop = M("goods_warehouse");
$info = $mop->where($whe)->select();
if ($info) {
$where[‘id‘] = array(‘in‘, $id);
$mod = M("goods_warehouse");
if ($mod->where($where)->delete()) {
$data = "Y";
}
} else {
$data = "N";
}
$this->ajaxReturn($data);
}
标签:asc check elements 选中 oca info ima var .ajax
原文地址:http://www.cnblogs.com/chenyufu/p/6879659.html