使用Jquery选择带大括号的id

发布于 2024-11-03 19:44:53 字数 519 浏览 4 评论 0原文

我有一个如此令人沮丧的问题,我相信有一个简单的答案。不幸的是我似乎无法在任何地方找到它!我有一个无法控制的表(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

清风不识月 2024-11-10 19:44:53

最简单的选择是调用 $(document.getElementById("{ACDC3234-D009-4889-931A-FCC069613AB6}-{EF2BF0FD-7927-4194-910F-0FE83EC4F118}"))

您还可以尝试使用 \ 字符转义大括号(这些字符本身必须在 JS 字符串文字中转义):

$('#\\{ACDC3234-D009-4889-931A-FCC069613AB6\\}-\\{EF2BF0FD-7927-4194-910F-0FE83EC4F118\\}')

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):

$('#\\{ACDC3234-D009-4889-931A-FCC069613AB6\\}-\\{EF2BF0FD-7927-4194-910F-0FE83EC4F118\\}')
下壹個目標 2024-11-10 19:44:53

另外,阅读文档有助于:

如果您想使用任何元字符(例如 !"#$%&'()*+,./:;<=>?@[\]^`{ |}~ )作为名称的文字部分,您必须使用两个反斜杠转义字符:\\

Just in addition, reading documentation helps:

If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]^`{|}~ ) as a literal part of a name, you must escape the character with two backslashes: \\.

方觉久 2024-11-10 19:44:53

由于它是无效 ID,因此您可能无法使用 ID 选择器。这可能会起作用:

$('table[id="{ACDC3234-D009-4889-931A-FCC069613AB6}-{EF2BF0FD-7927-4194-910F-0FE83EC4F118}"]')

现在您正在使用任何属性选择器(无论它叫什么)。由于您可以将任何内容放入属性中,因此您可以(我认为!)搜索它。

也许 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:

$('table[id="{ACDC3234-D009-4889-931A-FCC069613AB6}-{EF2BF0FD-7927-4194-910F-0FE83EC4F118}"]')

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/

爱你是孤单的心事 2024-11-10 19:44:53

该 ID 在 HTML4 中无效,因此您不能假设每个浏览器或工具都能够处理它。

来自规范

IDNAME 令牌必须以字母 ([A-Za-z]) 开头,后面可以跟任意数量的字母、数字 ([0-9])、连字符 ("-")、下划线 ("_")、冒号 (":") 和句点(“。”)。

然而,可能值得注意的是,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:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文