简体   繁体   English

单击时在每个tr行上切换类

[英]Toggle class on each tr row when clicked

For some reason I can't get the class of "selected" to toggle on when each row is clicked 由于某些原因,单击每一行时无法打开“选择”类

Example: http://jsfiddle.net/g8gumhg0/1/ 示例: http//jsfiddle.net/g8gumhg0/1/

jQuery: jQuery的:

$("tr").click(function() {
      $(this).toggleClass('selected');
};

CSS: CSS:

table tr.user:hover {
    background: #007A00;
}
table tr.selected {
    background: #198719;
}

Should be a simple fix, but I can't see what I'm doing wrong. 应该是一个简单的修复程序,但是我看不到我在做什么错。

$("tr").click(function() {
      $(this).toggleClass('selected');
});

You are missing a closing bracket at the end. 您最后缺少一个右括号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM