繁体   English   中英

单击添加类,并在再次单击该特定TR或跨度时删除

[英]Add class on click and remove when clicked again to that particular tr or span

当我单击任何内容时,它将选择表中的所有行,但我想特定于该单击。

我的js是-

$(document).ready(function() {
    //appendScroll(scrollbarElement = $('.acraft-panelgroup'))
    $("#runway-select > tr").click(function() {
        // $("#runway-select ").parent('td span').removeClass("activehero");
        $("#runway-select span").parent().toggleClass("activehero");
    });
})

我的html是-

<tbody id="runway-select">
    <tr class="text-center">
        <td><span class="glyphicon glyphicon-ok"></span>  </td>
        <td>04</td>
        <td>7102<span class="glyphicon glyphicon-info-sign"></span></td>
        <td><input type="text" class="form-control" /></td>
        <td></td>
</tbody>

如果可以的话,请帮助我。 我尝试使用Parent(),但是它不起作用。

 $(this).toggleClass("activehero");

这将在tr上切换类。

 $(this).find('span').toggleClass("activehero");

这将在tr内的每个span上切换类。

this事件处理程序中的对象将是当前目标。 这是您单击的HTML元素。

.find()搜索从指定目标.find()的指定元素。

我假设您想基于单击的行切换表列的类activehero ,如果是这样,则可以使用:

$("#runway-select > tr").click(function(){ 
    $(this).find('td').toggleClass("activehero");
});

暂无
暂无

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

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