不区分大小写的jQuery属性选择器 [英] Case insensitive jQuery attribute selector
本文介绍了不区分大小写的jQuery属性选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用属性包含选择器 $('[attribute * = value]'执行以下操作)
I am doing the following using attribute contains selector $('[attribute*=value]')
<input name="man-news">
<input name="milkMan">
<script>
$( "input[name*='man']").css("background-color:black");
</script>
这适用于第一个输入但不是第二个输入为男人 有一个大写 M
This works for the 1st input but not the second input as "Man" has a capital "M"
如何制作 $(input [name * ='man' ])
不区分大小写的选择器?
How can I make $( "input[name*='man']")
an case insensitive selector?
推荐答案
您始终可以使用 .filter()
:
var mans = $('input').filter(function() {
return $(this).attr('name').toLowerCase().indexOf('man') > -1;
});
mans.css('background-color', 'black');
这里的关键部分是 toLowerCase()
它会降低名称
属性,允许您测试它是否包含 man
。
The key part here is toLowerCase()
which lowercases the name
attribute, allowing you to test it for containing man
.
这篇关于不区分大小写的jQuery属性选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文