如何使用jQuery忽略大小写选择? [英] How do I use jQuery to ignore case when selecting?

查看:489
本文介绍了如何使用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忽略大小写选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆