gpt4 book ai didi

javascript - jquery过滤器 "a"带有条件的标签

转载 作者:行者123 更新时间:2023-11-27 23:56:35 26 4
gpt4 key购买 nike

我的代码有问题:

$('.tag').filter(function(){ return this.href.toLowerCase().match(/tagged\/large$/);}).hide();

$('.tag').filter(function(){ return this.href.toLowerCase().match(/tagged\/_large$/);}).hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="tag" href="/tagged/laRge">large</a>

我想在我的页面上隐藏href属性中包含“tagged/large”或“tagged/_large”的“a”标签,无论它是用大写字母还是小写字母书写。现在我在单独的脚本中拥有两个可能的链接,并且我希望将两个链接都放在一个脚本中,所以我想问您是否知道一种组合这两个脚本的方法?

最佳答案

通过添加问号,使下面的破折号在正则表达式中可选:

$('.tag').filter(function(){ return this.href.toLowerCase().match(/tagged\/_?large$/);}).hide();

关于javascript - jquery过滤器 "a"带有条件的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32212851/

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