如何使用jQuery忽略大小写选择?

编程入门 行业动态 更新时间:2024-10-09 01:23:50
本文介绍了如何使用jQuery忽略大小写选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正尝试使用以下jQuery选择器禁用链接:

I'm currently attempting to disable a link using the following jQuery selector:

$("a[href$=/sites/abcd/sectors]").removeAttr("href");

问题是,有时href在页面上可能不总是小写。当这种情况发生时,选择器不再匹配。

The problem is that sometimes the href might not always be lower case on the page. When this happens the selector no longer matches.

有人知道如何解决这个问题吗?

Does anyone know how to get around this? Can I change the behaviour this once to ignore case?

推荐答案

我自己碰到了这个问题。我切换逻辑一点,让我比较它没有case。它需要更多的工作,但至少它工作。

I ran into this myself. I switched the logic a bit to allow me to compare it without case. It requires a little more work, but at least it works.

$('a').each(function(i,n) { var href = $(n).attr("href"); href = href.toLowerCase(); if (href.endsWith('/sites/abcd/sectors')) $(n).removeAttr('href'); });

你必须找出自己的 endsWith 逻辑。

You would have to figure out your own endsWith logic.

更多推荐

如何使用jQuery忽略大小写选择?

本文发布于:2023-11-11 08:29:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577889.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:大小写   如何使用   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!