gpt4 book ai didi

javascript - 在选择器中连接

转载 作者:行者123 更新时间:2023-12-02 13:45:10 25 4
gpt4 key购买 nike

我预计选择器将是 $("a.3")但事实并非如此。

var giftId = '3';
$("a."+giftId).click(function() {
...
});

我不能这样吗?

即使类名不是以数字开头,它仍然不会连接

<a class="gift6"...

var giftId = '6';
$("a.gift"+giftId).click(...

最佳答案

您不能拥有以数字开头的类,这可以解释为什么这不起作用。

https://www.w3.org/TR/CSS2/syndata.html#value-def-identifier

In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier "B&W?" may be written as "B\&W\?" or "B\26 W\3F".

关于javascript - 在选择器中连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41462438/

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