如何使用jQuery排除ID以特定后缀结尾的元素 [英] How do I exclude elements whose ID ends in a certain suffix using jQuery
本文介绍了如何使用jQuery排除ID以特定后缀结尾的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个jQuery函数:
I have this jQuery function:
$(this).change(function(){
alert('I changed. ID: ' + $(this).attr("id"));
});
当ID名称以-0
结尾时,我需要发出警报以发出 except .我认为我应该使用$=
运算符.我不知道如何使它工作.
I need the alert to fire except when the id name ends in -0
. I think I should be using the $=
operator. I cannot figure out how to make it work.
推荐答案
您的选择器应使用 :not()
与属性-终点-with ($=
)组合看起来像这样:
Your selector should use :not()
combined with attribute-ends-with ($=
) look like this:
$(":not([id$='-0'])")
最好在其前面加上 something ,这样它不会针对每个元素,类或元素标签等运行,如下所示:
It's better to have something in front of that so it doesn't run against every element, a class or an element tag, etc, like this:
$(".myClass:not([id$='-0'])")
这篇关于如何使用jQuery排除ID以特定后缀结尾的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文