是否有自动将类添加到任何设置为哈希(#)的HREF?
我在Concrete5中使用了一个自动菜单,所以不幸的是它不能硬编码。
我会猜测并说它将是必须使用的JavaScript / jQuery?
提前致谢!
答案 0 :(得分:3)
答案 1 :(得分:1)
您可以尝试使用
$('a[href$="#"]').addClass('className');
选中docs以查看属性选择器的选项:
Attribute Contains Prefix Selector [name|="value"] Selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-). Attribute Contains Selector [name*="value"] Selects elements that have the specified attribute with a value containing the a given substring. Attribute Contains Word Selector [name~="value"] Selects elements that have the specified attribute with a value containing a given word, delimited by spaces. Attribute Ends With Selector [name$="value"] Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive. Attribute Equals Selector [name="value"] Selects elements that have the specified attribute with a value exactly equal to a certain value. Attribute Not Equal Selector [name!="value"] Select elements that either don’t have the specified attribute, or do have the specified attribute but not with a certain value. Attribute Starts With Selector [name^="value"] Selects elements that have the specified attribute with a value beginning exactly with a given string. Has Attribute Selector [name] Selects elements that have the specified attribute, with any value. Multiple Attribute Selector [name="value"][name2="value2"] Matches elements that match all of the specified attribute filters.
答案 2 :(得分:0)