gpt4 book ai didi

javascript - jQuery 添加类到 xlink :href

转载 作者:行者123 更新时间:2023-11-30 10:16:16 26 4
gpt4 key购买 nike

$('a[xlink:href=#'+value.id+']').addClass("foo");

我有一个 svg,里面有 <a xlink:href="#21" xlink:title="21"></a>围绕多边形。

我想做的是向 a 添加一个类xlink:href在哪里与 value.id 匹配

最佳答案

在使用双反斜杠将元字符用作选择器之前,您必须对其进行转义。

这样做:

$('a[xlink\\:href=#'+value.id+']').addClass("foo");

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 - jQuery 添加类到 xlink :href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23544479/

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