【DRP】 表格—对于行的操作
<input type="checkbox" name="ifAll" onClick="checkAll(this)">
<input type="checkbox" name="selectFlag" class="checkbox1" value="1001"> <input type="checkbox" name="selectFlag" class="checkbox1" value="1002"> <input type="checkbox" name="selectFlag" class="checkbox1" value="1003">
【全选和取消全选】
1 function checkAll(field) { 2 var selectFlags = document.getElementsByName("selectFlag"); 3 for (var i=0; i<selectFlags.length; i++) { 4 selectFlags[i].checked = field.checked; 5 } 6 }
【修改选中行】
1 function modifyUser() { 2 var selectFlags = document.getElementsByName("selectFlag"); 3 var count = 0; 4 var j = 0; 5 for (var i=0; i<selectFlags.length; i++) { 6 if (selectFlags[i].checked) { 7 j = i; 8 count++; 9 } 10 } 11 if (count == 0) { 12 alert("请选择需要修改的用户!"); 13 return; 14 } 15 if (count > 1) { 16 alert("一次只能修改一个用户!"); 17 return; 18 } 19 window.self.location = "user_modify.jsp?userId=" + selectFlags[j].value; 20 } 21
【删除选中行】
1 function deleteUser() { 2 var selectFlags = document.getElementsByName("selectFlag"); 3 var flag = false; 4 for (var i=0; i<selectFlags.length; i++) { 5 if (selectFlags[i].checked) { 6 flag = true; 7 break; 8 } 9 } 10 if (!flag) { 11 alert("请选择需要删除的用户!"); 12 return; 13 } 14 if (window.confirm("确认删除吗?")) { 15 with (document.getElementById("userform")) { 16 action="user_maint.jsp?command=del"; 17 method="post"; 18 submit(); 19 } 20 } 21 }
总结:不断提高自己的编码效率!