问题
I've got <span id="/about-us">
being generated by this CMS I'm using.
I'd like to select this element with jQuery but it doesn't seem to like selecting elements with a slash in them.
Is this possible?
回答1:
you can do
$("#\\/about-us")
回答2:
you can do it like this
$("span[id*='/about-us']")
where it will return the span with '/about-us' in it's id attribute.
回答3:
Use the regular way:
document.getElementById('id/with/slashes')
回答4:
see
Regex Selector for jQuery
or related question
回答5:
You can use jQuery escapeSeletor to do this.
$("#" + $.escapeSelector("id/with/slashes"))
来源:https://stackoverflow.com/questions/5153986/css-selector-to-select-an-id-with-a-slash-in-the-id-name