我正在尝试根据名称检索 DOM 元素。不幸的是,它们的名称中包含花括号 {}
。
jQuery (1.6.4) 能够毫无问题地检索它们。但此时我正尝试用 getElementsByName()
替换这些调用,但 gEBN 不匹配查询字符串中包含大括号的任何内容。我试过反斜杠转义它一次又两次都无济于事。
有没有办法在不改变使用大括号的约定的情况下做到这一点?
It also looks like它们不在名称 attr 中允许的字符集中。
更新:似乎适用于 Chrome 但不适用于 Windows 的 Safari。但真正奇怪的是,即使是 Windows 版 Safari 也能很好地处理这些问题。
最佳答案
如果您阅读 selectors 上的 jQuery 文档页面,你会看到这个:
To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes:
\\
. For example, an element with id="foo.bar", can use the selector$("#foo\\.bar")
.
关于javascript - HTML 名称属性中的大括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16202468/