AI智能
改变未来

asp.net mvc checkbox 全选/反选 多选获取值


asp.net mvc checkbox 全选/反选 多选获取值

1.创建隐藏域<tr><td><input type=\"hidden\" name=\"checkValue\" id=\"checkValue\" value=\"\" /></td></tr><tr><td><input type=\"checkbox\" name=\"checkAll\" id=\"checkAll\" onclick=\"swapCheck()\" /></td></tr>2.写js<script type=\"text/javascript\">//checkbox 全选/取消全选var isCheckAll = false;function swapCheck() {if (isCheckAll) {$(\"input[type=\'checkbox\']\").each(function () {this.checked = false;Getcheckbox();});isCheckAll = false;} else {$(\"input[type=\'checkbox\']\").each(function () {this.checked = true;Getcheckbox();});isCheckAll = true;}}function Getcheckbox() {var str = document.getElementsByName(\"checkId\");var objarray = str.length;var chestr = \"\";for (i = 0; i < objarray; i++) {if (str[i].checked == true) {chestr += str[i].value + \":\";}}document.getElementById(\"checkValue\").value = chestr;}</script>3.拼接字符串str += \"<td><input type=\'checkbox\' name=\'checkId\' id=\'checkId\' οnchange=\'Getcheckbox()\' /></td>\";
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » asp.net mvc checkbox 全选/反选 多选获取值