【问题标题】:How to append one more class to exisiting one in Jquery如何在 Jquery 中将一个类附加到现有的类
【发布时间】:2016-02-20 07:42:48
【问题描述】:

我想使用 jQuery 将一个类绑定到 tr。 tr 如下所示:

<tr id="@item[1]">
    <td>@item[0]</td>
    <td>@item[1]</td>
</tr>

加载tr上面的数据后如下:

<tr class="even" id="1">
    <td>AAA</td>
    <td>BBB</td>
</tr>

在这里,我想在我的 tr 中再添加一个类“read_only”,如下所示:

<tr class="read_only even" id="1">
    <td>AAA</td>
    <td>BBB</td>
</tr>

如何在 jQuery 中做到这一点?

【问题讨论】:

  • $(".even").addClass("read_only") ??
  • 用 google 进行非常简单的搜索就绰绰有余了。去谷歌,输入“jquery add class to element”并点击第一个结果
  • &lt;tr class="read_only @item[1]"&gt; ?
  • 我知道这是简单直接的,但在我的案例中,“偶数”类在运行时添加到 tr 中。所以我的问题是如何动态添加一个类。在设计中,我只知道每个 tr 的 id。
  • 你试过什么?你是什​​么意思偶数类被添加到“运行时”?为什么 ID 很重要?

标签: javascript jquery html classname


【解决方案1】:
$(".even").addClass("read_only")

【讨论】:

    猜你喜欢
    • 2012-12-14
    • 1970-01-01
    • 2020-10-28
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    • 2016-12-09
    • 1970-01-01
    • 2020-08-19
    相关资源
    最近更新 更多