javascript - Meteor - 如何使单击的表格行保持突出显示的颜色

标签 javascript css meteor

我有以下 meteor.js 模板:

<template name="users">

    <div class="container-fluid">
        <div class="row-fluid"> 
            <div class="page-header">
              <h1><small>Users List</small></h1>
            </div>

            <table class="table table-bordered table-striped table-hover">
                <thead>
                    <tr>
                        <th>Name</th>
                    </tr>
                </thead>
                <tbody>
                   {{#each userList}}
                    {{>userRow}}
                   {{/each}}
                </tbody>
            </table>
        </div>
    </div>
</template>
<template name="userRow">
     <tr class="userRow">
        <td>{{name}}</td>
     </tr>
</template>

这是相应的事件处理程序:

Template.userRow.events({
    'click .userRow':function(evt,tmpl){
        console.log(tmpl.data.name);

    }
});

这是CSS:

.table-striped tbody tr.highlight td {
    background-color: red;
}

.table-hover>tbody>tr:hover>td, .table-hover>tbody>tr:hover>th {
  background-color: #550055;
  color:#eeeeee;
}

悬停时突出显示效果很好,但是,当单击特定行时,当鼠标悬停时它不会保留其突出显示的颜色。

我该怎么做才能解决这个问题?

最佳答案

假设你想将 highlight 类添加到 userRow,你可以尝试这样的事情:

Template.userRow.events({
  'click .userRow': function(e) {
    console.log(this.name);
    $('.userRow').removeClass('highlight');
    $(e.currentTarget).addClass('highlight');
  }
});

关于javascript - Meteor - 如何使单击的表格行保持突出显示的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22885822/

相关文章:

javascript - Meteor Template.myTemplate.helpers 不渲染输出

cordova - 如何使用 Meteor 在 iOS 中打开谷歌地图

javascript - 如何更改包含所选 .class 的 div #id 的样式

html - 使用 Flexbox 时,子 div 高度应等于其父级高度

javascript - 辅助方法无法使用 setState 设置增量 id

jquery-ui 调整一个元素的大小会影响其他元素

css - AngularJS 破坏了 Foundation 模态。解决方法?

meteor - Template.instance() 和这个的区别

javascript - 关闭事件类的子菜单

javascript - 大json请求外部url