$(document).ready(function () { //排序文本框限输入整数 $("input[id^='sort']").keydown(function () { var e = $(this).event || window.event; var code = parseInt(e.keyCode); if (code >= 96 && code <= 105 || code >= 48 && code <= 57 || code == 8) { return true; } else { return false; } }); //全选,反选 $("#all").click(function () { $.each($("input[type='checkbox'][id!=all]"), function (k, v) { v.checked = $("#all").attr("checked"); //v.checked = $("#all")[0].checked; }); }); ps:
$(function(){ //全选与全不选 $("#ckall").click(function(){ $("[name=ck]:checkbox").attr("checked",this.checked); }); var objs=$("[name=ck]:checkbox"); objs.click(function(){ $("#ckall").attr("checked",objs.length==objs.filter(":checked").length); }); // });<input type="checkbox" id="ckall" />
<input type="checkbox" name="ck" />
<input type="checkbox" name="ck" />
<input type="checkbox" name="ck" />
<input type="checkbox" name="ck" />
//批量删除 $("#largeDel").click(function () { var str = ""; $.each($("input[type='checkbox'][id!=all]"), function (k, v) { if (v.checked == false) { return; } else { str += v.value + ","; } }); if (str == "") { alert("请选中一项"); return; } else if (confirm("确认删除吗?")) { str = str.substring(0, str.length - 1); window.location.href = "BatchRemove.aspx?ids=" + str; } }); //设置排序 $("#setSort").click(function () { var regNum = /^\d*$/; var strId = ""; var strSort = ""; var istrue = true; $.each($("input[id^='sort']"), function (k, v) { if (v.value.length < 1) { $(this).css("border", "1px solid red").focus(); return istrue = false; } else if (v.value.length > 0) { $(this).css("border", "1px solid black"); strSort += v.value + ","; strId += v.id.replace("sort", "") + ","; } }); if (istrue) { strId = strId.substring(0, strId.length - 1); strSort = strSort.substring(0, strSort.length - 1); window.location.href = "SetSort.aspx?strId=" + strId + "&strSort=" + strSort; } }); //and so so });