分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

Jquery,全选,反选,

发布时间:2023-09-06 02:18责任编辑:胡小海关键词:暂无标签
<!DOCTYPE html><html> ?<head> ???<meta charset="utf-8"> ???<title></title> ???<script src="/vue/js/jquery-3.3.1.js" type="text/javascript"> ?</script> ???<script type="text/javascript"> ???$(function () ???{ ??????//所有复选选中让 全选的复选框选中 ?????$("table tr td input[type=‘checkbox‘]").click(function(){ ?????????var check= $("table tr td input[type=‘checkbox‘]:checked").length; ?????????var all=$("table tr td input[type=‘checkbox‘]").length; ?????????if(check==all) ?????????{ ???????????$("#all").prop("checked",true) ?????????} ?????????else { ???????????$("#all").prop("checked",false) ?????????} ?????}) ???????$("#all").click(function(){ ?????????var c= ?$("#all").prop("checked") ?????????if (c==true) { ???????????$("table tr td input[type=‘checkbox‘]").prop("checked",true) ?????????} ?????????else { ?????????????$("table tr td input[type=‘checkbox‘]").prop("checked",false) ?????????} ???????}) ?//反选按钮 ?????$("#selectno").click(function(){ ???????//获取所有未选中行的checkbox长度 ?????var no= ?$("table tr td input[type=‘checkbox‘]:not(:checked)").length ?????????//获取所有选中行的checkbox长度 ?????var yes= $("table tr td input[type=‘checkbox‘]:checked").length ???????????alert( ‘选中长度‘+yes) ???????????alert(‘未选中长度‘+no) ???????????$("table tr td input[type=‘checkbox‘]").each(function(){ ???????????$(this).prop("checked",!$(this).prop("checked")) ???????????}) ???????}) ???}) ???</script> ?</head> ?<body> ???全选:<input type="checkbox" id="all" > ???<input type="button" id="selectno" value="反选" ><table> ?<tr> ???<td>状态</td> ??<td>姓名</td> ??<td>工资</td> ?</tr> ?<tr> ???<td> <input type="checkbox" name="" value=""> </td> ???<td>张三</td> ???<td>2000</td> ?</tr> ?<tr> ????<td> <input type="checkbox" name="" value=""> </td> ????<td>李四</td> ????<td>200</td> ?</tr> ?<tr> ????<td> <input type="checkbox" name="" value=""> </td> ????<td>王五</td> ????<td>200</td> ?</tr> ?<tr> ????<td> <input type="checkbox" name="" value=""> </td> ????<td>赵六</td> ????<td>200</td> ?</tr> ?<tr> ????<td> <input type="checkbox" name="" value=""> </td> ????<td>田七</td> ????<td>200</td> ?</tr> ?<tr> ????<td> <input type="checkbox" name="" value=""> </td> ????<td>王八</td> ????<td>200</td> ?</tr></table> ?</body></html>

Jquery,全选,反选,

原文地址:https://www.cnblogs.com/tianranhui/p/9813729.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved