gpt4 book ai didi

jquery live 和 : problem

转载 作者:行者123 更新时间:2023-12-01 06:40:39 24 4
gpt4 key购买 nike

$('#ptadsd1:r1:0:cbN89').live('click', function(event1) { 
alert('clicked');
return false;
});

不起作用,因为 jdeveloper 在创建 ID 时使用“:”。

例如,

我的 ID 是“ptadsd1:r1:0:cbN89”。 Jdeveloper 在创建 ids 时使用“:”,但 jquery 有问题。如何解决“:”的问题?

最佳答案

您需要使用 \ 转义 :。但为了防止 JavaScript 将 \: 视为单个字符,您需要对其进行双重转义:

$('#ptadsd1\\:r1\\:0\\:cbN89');
<小时/>

相关引用:

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: \\. For example, if you have an an element with id="foo.bar", you can use the selector $("#foo\\.bar").

http://api.jquery.com/category/selectors/

关于jquery live 和 : problem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4782123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com