チェックボックスをクリックしてスタイルを追加し、チェックした行の色の変更効果の実装方法を紹介します。具体的な実装方法は次のとおりです table { border: 0; border-collapse: collapse; } td { font: normal 12px/17px Arial; padding: 2px; width: 100px; } th { font: bold 12px/17px Arial; text-align: left; padding: 4px; border-bottom: 1px solid #333; } .even { background: #FFF38F; }/* 偶数行样式*/.odd { background: #FFFFEE; }/* 奇数行样式*/.selected { background: #FF6500; color: #fff; } $(function () { $("tbody tr:even").addClass("even"); $("tbody tr:odd").addClass("odd"); $(":checkbox").change(function () {if ($(this).is(":checked")) { $(this).parents("tr").addClass("selected"); }else{ $(this).parents("tr").removeClass("selected"); } });//初始化默认选中色selected样式$(":checkbox").each(function () {if ($(this).is(":checked")) { $(this).parents("tr").addClass("selected"); } }) }) 姓名 性别 暂住地 张山 男 浙江宁波 李四 女 浙江杭州 王五 男 湖南长沙 找六 男 浙江温州 Rain 男 浙江杭州 MAXMAN 女 浙江杭州 ログイン後にコピー //スタイルを追加する行をクリックしてください table {border: 0;border-collapse: collapse;}td {font: normal 12px/17px Arial;padding: 2px;width: 100px;}th {font: bold 12px/17px Arial;text-align: left;padding: 4px;border-bottom: 1px solid #333;}.even {background: #FFF38F;}/* 偶数行样式*/.odd {background: #FFFFEE;}/* 奇数行样式*/.selected {background: #FF6500;color: #fff;}$(function () { $("tbody tr:even").addClass("even"); $("tbody tr:odd").addClass("odd"); $("tbody tr").click(function () {var hasselect = $(this).hasClass("selected");if (hasselect) { $(this).removeClass("selected"); $(this).find("input").attr("checked", false); } else { $(this).addClass("selected"); $(this).find("input").attr("checked", true); } }) $('tbody>tr:has(:checked)').addClass('selected');// $(":checkbox").each(function () {// if ($(this).is(":checked")) {// $(this).parents("tr").addClass("selected");// }// })})姓名性别暂住地张山男浙江宁波李四女浙江杭州王五男湖南长沙找六男浙江温州Rain男浙江杭州MAXMAN女浙江杭州ログイン後にコピー 。