$(function(){ // 全选/反选 $("#tableID").on("click", "th input[type='checkbox']", function(){ var isChecked = $(this).prop("checked"); $("#tableID").find("td input[type='checkbox']").prop("checked", isChecked); }); $("#tableID").on("click", "td input[type='checkbox']", function(){ var isChecked = $(this).prop("checked"); if(!isChecked){ $("#tableID").find("th input[type='checkbox']").prop("checked", false); }else{ var allChecked = true; $("#tableID").find("td input[type='checkbox']").each(function(){ if(!$(this).prop("checked")){ allChecked = false; return false; } }); if(allChecked){ $("#tableID").find("th input[type='checkbox']").prop("checked", true); } } });

// 添加数据 $("#addID").click(function(){ var username = $("#usernameID").val(); var tell = $("#tell").val(); if(username == "" || tell == ""){ alert("用户名和号码为必填项!"); return; } var trHtml = ""+username+""+tell+"删除"; $("#tbodyID").append(trHtml); $("#usernameID").val(""); $("#tell").val(""); });

// 删除数据 $("#delID").click(function(){ $("#tableID").find("td input[type='checkbox']:checked").each(function(){ $(this).closest("tr").remove(); }); $("#tableID").find("th input[type='checkbox']").prop("checked", false); });

// 删除单条数据 $("#tableID").on("click", "td a", function(){ $(this).closest("tr").remove(); }); })

1、请在下面的HTML页面中加入jQuery代码实现如下图的效果。部分HTML代码:style			td				text-align center;					style	head	body		 table id=tableID border=1 align=center width=80		 tr					thinput type=checkbox全选th

原文地址: https://www.cveoy.top/t/topic/cKVx 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录