首页 > 代码库 > MVC 复选框全选 添加到数据库方法
MVC 复选框全选 添加到数据库方法
<li><input onclick="selectAll(this);" type="checkbox" name="controlAll" id="controlAll" /><label>全选</label></li>
<li><input name="itemname" type="checkbox" value="http://www.mamicode.com/@item.ProjectId" /><label>@item.Name</label></li>
function selectAll(obj) {
var status = $(obj).prop("checked");
//alert(status);
var checklist = document.getElementsByName("itemname");
if (document.getElementById("controlAll").checked) {
myconfirm("确定要分配全部项目吗?", "");
$("#confirmBtnDetermine").click(function () {
var projectId = "";
for (var i = 0; i < checklist.length; i++) {
if (checklist[i].checked == 0) {
checklist[i].checked = 1;
projectId += ","+checklist[i].value;
} }
// alert(projectId);
$.ajax({
type: "POST",
url: ‘@Url.Action("AllAddEditSubmit", "Permission")‘,
dataType: "json",
data: { projectId: projectId, employeeId: ‘@ViewBag.EmployeeId‘,status: status },
success: function (data) {
if (data.Result) {
myalert(data.Message, "");
} else {
myalert(data.Message, "");
}
}
});
})
}
else {
myconfirm("确定要取消所有项目权限吗?", "");
$("#confirmBtnDetermine").click(function () {
var projectId = "";
for (var j = 0; j < checklist.length; j++) {
checklist[j].checked = 0;
projectId += "," + checklist[j].value;
}
$.ajax({
type: "POST",
url: ‘@Url.Action("AllAddEditSubmit", "Permission")‘,
dataType: "json",
data: { projectId: projectId, employeeId: ‘@ViewBag.EmployeeId‘,status: status },
success: function (data) {
if (data.Result) {
myalert(data.Message, "");
} else {
myalert(data.Message, "");
} } });
}); } }
MVC 复选框全选 添加到数据库方法