jQuery :选择每个具有不同特定属性的元素

jQuery : selects each element with different specific attributes

我需要定位具有 target=_blank 而不是 .pdf 文件的 au 链接。

目前,我正在这样做,效果很好:

$('a[target=_blank]').click(function (e) {
 if (this.href.split('.').pop() !== 'pdf') {
     // do something
 }
});

我想知道是否可以使用 jQuery [attribute$=value] 选择器:$("a[href$='.pdf']") 类似于:

("a[href$!='.pdf']")

我问是因为我发现这种语法使用起来非常简单。

您可以使用:not() selector

$('a[target=_blank]:not([href$=".pdf"])')