gpt4 book ai didi

javascript - Jquery - 检查链接表达式问题中的 href?

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

我坚持检查地址是否包含变量的表达式。 Jquery 返回错误:无法识别的表达式:.ui-body h3 a[href*=/65_]。你能帮我解决这个问题吗?非常感谢。PS:由于链接中的口是心非,我需要在带有数字和下划线的 href 表达式中使用斜杠。表达式中的斜线是个问题!

J查询:

num_id = 65
$(".ui-body h2 a[href*=\/" + num_id + "]_").first().parent().parent().parent().append($(this));

HTML: ..内容

<div class="col-bottom-1">
<div class="ui-body">
<h2>
<a href="/65_news.html">Text</a>
<a href="/65_news.html">&gt;&gt;</a>
</h2>
</div>
<!-- this is place where I display div after Jquery function -->
</div>

最佳答案

您必须转义您的 / 才能将其用作选择器,并且您的 _ 必须位于 href 属性选择器内。

Ref :

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"). The W3C CSS specification contains the complete set of rules regarding valid CSS selectors. Also useful is the blog entry by Mathias Bynens on CSS character escape sequences for identifiers.

喜欢:

num_id = 65
$(".ui-body h2 a[href*=\\/" + num_id + "_]").first().parent().parent().parent().append($(this));

演示:http://jsfiddle.net/IrvinDominin/GUDYN/

关于javascript - Jquery - 检查链接表达式问题中的 href?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22723226/

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