我正在尝试添加一个基于以特定 a href 开头的表格单元格的类。
这是 HTML:
<tr class="odd">
<td class=" sorting_1">
<a href="/workorders/1">13-10000</a>
</td>
我以为这会起作用,但事实并非如此:
$('a[href$^="/workorders/"]').addClass("boldnowrap");
我实际上正在使用 CoffeeScript :
$('a[href$^="/workorders/"]').addClass "boldnowrap"
谢谢!
最佳答案
[href$^="..."]
部分是无效选择器。
我认为您正在寻找其中之一:
$('a[href^="/workorders/"]').addClass("boldnowrap");
$('a[href*="/workorders/"]').addClass("boldnowrap");
请注意,每次在 href
中找到 /workorders/
时,第二个都会匹配,可能不是您想要的。
关于Jquery基于href添加类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16987866/