Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 选择表行并使用Twitter引导保持高亮显示_Jquery_Css_Twitter Bootstrap_Twitter Bootstrap 3 - Fatal编程技术网

Jquery 选择表行并使用Twitter引导保持高亮显示

Jquery 选择表行并使用Twitter引导保持高亮显示,jquery,css,twitter-bootstrap,twitter-bootstrap-3,Jquery,Css,Twitter Bootstrap,Twitter Bootstrap 3,我使用的是一个Twitter引导表,当鼠标悬停在上面时,它会突出显示可点击的行。如果它能让这变得更容易的话,我可以去掉鼠标悬停功能。我希望所选行保持高亮显示,直到单击另一行或重新单击该行 $( document ).ready(function() { $('#myTable').on('click', 'tbody tr', function(event) { // console.log("test ");

我使用的是一个Twitter引导表,当鼠标悬停在上面时,它会突出显示可点击的行。如果它能让这变得更容易的话,我可以去掉鼠标悬停功能。我希望所选行保持高亮显示,直到单击另一行或重新单击该行

    $( document ).ready(function() {
        $('#myTable').on('click', 'tbody tr', function(event) {
            //  console.log("test ");                   
        });
桌子呢

<table class="table table-bordered table-hover" id="myTable">
    <tbody>
        <tr>
        <tr class='clickable-row'>

你很接近。目标是$myTable上的.clickable行类。在。。。事件和使用引导的.active类应该适合您:

HTML:

注意:如果将.table悬停在表上,则必须使用与.active不同的类,例如.bg info,它将是一个

要从行中删除突出显示,请再次单击,检查该行是否具有类并将其删除:

$('#myTable').on('click', '.clickable-row', function(event) {
  if($(this).hasClass('active')){
    $(this).removeClass('active'); 
  } else {
    $(this).addClass('active').siblings().removeClass('active');
  }
});
有关原始信息,请参见@BravoZulu的答案。

尝试:

$(".clickable-row").click(function(){
    if($(this).hasClass("highlight"))
        $(this).removeClass('highlight');
    else
        $(this).addClass('highlight').siblings().removeClass('highlight');
})

我在引导表上使用了这个脚本

$('#tb-pegawai').on('change', 'tr' , function (event) {
            if($('.selected')){ // } })

要显示颜色的绘制行,表示已选中该行,可以使用数据行样式='formatterRowUtSelect'

在代码中,可以添加以下方法:

formatterRowUtSelect = function (row, index) {
    if (row.fieldOfMyObject == $ ('#fieldOfMyObject'). val ())
        return {classes: 'row-selected'};
    return {};
}
不要忘记为所选行创建css:

.row-selected {
    background-color: #a9f0ff !important;
    font-weight: bold;
}

我希望它能为您服务,您好。

重新单击该行不会取消选择。此解决方案存在一个错误-准确地说,您可以每页选择多行。使用表$'tr.active'。删除类'active';似乎解决了这个问题。这是toggleClass很方便的地方。欢迎使用堆栈溢出!如果您还没有,请随时查看和。另外,我会注意到,使用函数声明,即函数foo{…},而不是像foo=function{…}这样的隐式全局赋值,通常更惯用。这样做的另一个好处是。
$('#tb-pegawai').on('change', 'tr' , function (event) {
            if($('.selected')){ // } })
formatterRowUtSelect = function (row, index) {
    if (row.fieldOfMyObject == $ ('#fieldOfMyObject'). val ())
        return {classes: 'row-selected'};
    return {};
}
.row-selected {
    background-color: #a9f0ff !important;
    font-weight: bold;
}