使用Jquery选择带大括号的id
我有一个如此令人沮丧的问题,我相信有一个简单的答案。不幸的是我似乎无法在任何地方找到它!我有一个无法控制的表(SharePoint),并且已分配的表 ID 包含大括号:
例如
如何使用 JQuery 选择表,同时保留括号?
目前的代码是:
$(function(){
$('/{#{ACAC3258-D068-4799-931A-FCC069613AB6}-{EF2BF0FD-7927-4194-910F-0FE83EC4F118}}/').visualize({type: 'bar', width: '420px'});
});
我正在尝试使用 JQuery 图形工具 Visualise。
对此的任何帮助将非常感激!
非常感谢!
I've got such a frustrating question for which I'm convinced there is an easy answer. Unfortunately I can't seem to find it anywhere! I have a table which I have no control over (SharePoint) and the table ID which has been allocated contains curly brackets:
e.g. <table id="{ACDC3234-D009-4889-931A-FCC069613AB6}-{EF2BF0FD-7927-4194-910F-0FE83EC4F118}"></table>
How can I select the table using JQuery whilst maintaining the brackets?
The code as it stands is:
$(function(){
$('/{#{ACAC3258-D068-4799-931A-FCC069613AB6}-{EF2BF0FD-7927-4194-910F-0FE83EC4F118}}/').visualize({type: 'bar', width: '420px'});
});
I am trying to use JQuery Graphing Tool, Visualise.
Any help on this would be really greatly appreciated!
Many Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最简单的选择是调用
$(document.getElementById("{ACDC3234-D009-4889-931A-FCC069613AB6}-{EF2BF0FD-7927-4194-910F-0FE83EC4F118}"))
。您还可以尝试使用
\
字符转义大括号(这些字符本身必须在 JS 字符串文字中转义):The simplest option is to call
$(document.getElementById("{ACDC3234-D009-4889-931A-FCC069613AB6}-{EF2BF0FD-7927-4194-910F-0FE83EC4F118}"))
.You can also try escaping the braces with
\
characters (which must themselves be escaped in the JS string literal):另外,阅读文档有助于:
Just in addition, reading documentation helps:
由于它是无效 ID,因此您可能无法使用 ID 选择器。这可能会起作用:
现在您正在使用任何属性选择器(无论它叫什么)。由于您可以将任何内容放入属性中,因此您可以(我认为!)搜索它。
也许 jQuery 不允许...
编辑
jQuery 1.3.2 允许: http://jsfiddle.net/rudiedirkx/VHpFb/
Since it's an invalid ID, you probably can't use the ID selector. This might work though:
Now you're using any-attribute-selector (whatever that's called). Since you can put anything in an attribute, you can (I think!) search for it.
Maybe jQuery won't allow it...
edit
jQuery 1.3.2 allows it: http://jsfiddle.net/rudiedirkx/VHpFb/
该 ID 在 HTML4 中无效,因此您不能假设每个浏览器或工具都能够处理它。
来自规范:
然而,可能值得注意的是,HTML5(部分是现有浏览器处理 HTML 方式的重新标准化)确实删除了这些限制,因此尽管我发出了警告,但很可能还有另一种解决方案,它会更有效。
That ID is invalid in HTML4 and for that reason you can't assume that every browser or tool will be able to process it.
From the spec:
However, it's probably worth noting that HTML5 (which is partially a restandardisation of how existing browsers treat HTML) does remove those restrictions, so despite my warning it's likely that there is another solution which will work more often than not.