前台页面(JQuery)
@*全选&批删*@
<script type="text/javascript">
$(document).ready(function () {
// 全选
$("#selectAll").click(function () {
$("input[name='RKEY']").prop("checked", this.checked);
});
// 单选
var subChk = $("input[name='RKEY']")
subChk.click(function () {
$("#selectAll").prop("checked", subChk.length == subChk.filter(":checked").length ? true : false);
});
/* 批量删除 */
$("#DeleteBtn").click(function () {
// 判断是否至少选择一项
var checkedNum = $("input[name='RKEY']:checked").length;
if (checkedNum == 0) {
alert("至少选择一项!");
return;
}
// 批量选择
if (confirm("确定要删除所选项目?")) {
var checkedList = new Array();
$("input[name='RKEY']:checked").each(function () {
checkedList.push($(this).val());
});
$.ajax({
type: "POST",
url: "/Home/V_Dels",
data: { 'delitemsss': checkedList.toString() },
dataType: "text",
success: function (result) {
alert(result);
$("[name ='RKEY']:checkbox").attr("checked", false);
window.location.reload();
}
});
}
});
});
</script>
前台页面(H5)
<table class="table table-hover" style="100%;font-size:30%;margin-top:1%;border-top:1px solid gray;border-left:1px solid gray;border-bottom:1px solid gray">
<thead>
<tr>
<th> <input type="checkbox" id="selectAll" name="selectAll" style="" /></th>
<td>ID</td>
</tr>
</thead>
<tbody>
@*显示*@
@foreach (var item in Model)
{
<tr>
<th><input type="checkbox" id="RKEY" name="RKEY" value="@item.V_Id" /></th>
<td>@item.V_Id</td>
</tr>
}
</tbody>
</table>
控制器
//批量删除
public ActionResult V_Dels()
{
ArrayList arr = new ArrayList();
string rkeyStr = "";
StringBuilder sb = new StringBuilder();
if (Request["delitemsss"] != null && Request["delitemsss"].ToString() != "")
{
rkeyStr = Request["delitemsss"].ToString();
string[] rkeyArr = rkeyStr.Split(',');
int count = 0;
for (int i = 0; i < rkeyArr.Length; i++)
{
count = bll.ValueTab_Del(Convert.ToInt32(rkeyArr[i]));
}
if (count > 0)
{
string str = "删除成功!";
return Content(str);
}
else
{
rkeyStr = "";
string str = "删除失败!";
return Content(str);
}
}
return null;
}