我知道有很多关于此的帖子,但我不知道为什么我的不起作用。
我试图突出显示表中的一行:
<tr class="videorow"><td>...</td>...</tr>
...
css:
.highlight {
background-color: #a8cb17;
}
最后是我的 jQuery:
jQuery(document).on("click", ".videorow", function() {
//highlight table
jQuery(".highlight").removeClass("highlight");
jQuery(this).addClass("highlight");
});
基本上我想突出显示一行并在选择新行时清除。这是我什至无法弄清楚的第一部分。
此外,我想突出显示整行,但我不希望最后一列触发突出显示。换句话说,您可以单击该行的最后一列,但这不会改变突出显示。
就像是:
jQuery(document).on("click", ".videorow", function() {
//highlight table
jQuery(".highlight").removeClass("highlight");
jQuery('table tr td:not(:last-child)').addClass("highlight");
});
任何关于这两个问题的指导都是值得赞赏的。
EDIT: 打字太快了。语法错误只是我写出来而不是复制......现在已修复
jQuery(document).on("click", "tr.videorow > td", function() {
var $this = jQuery(this);
// ignore clicks on last column
if ( $this.is(":last-child") ) return;
// unhighlight currently selected row
jQuery(".highlight").removeClass("highlight");
// change the highlight of the row
$this.parent().addClass("highlight");
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)