jQuery-查找没有目标或特定目标的链接 [英] Jquery - find links that have no target or a certain target
问题描述
我想找到页面上所有没有目标属性或等于' pageContent '的目标属性的链接,对于所有匹配的元素,我想要对他们应用onclick
事件.
I'd like to find all the links on a page that either have no target attribute or a target attribute that equals 'pageContent' and for all matched elements I would like to apply an onclick
event to them.
onclick
事件称为pgTrans('start')
.我不确定是否重要,但是某些链接可能已经通过jQuery对该代码进行了硬编码或附加了该事件.
The onclick
event is called pgTrans('start')
. I'm not sure if it matters but some of the links may already have this event hard coded or attached via jQuery.
推荐答案
尝试以下操作:
$('a:not([target]), a[target="pageContent"]').click(function(e) {
e.preventDefault();
pgTrans('start');
});
演示: http://jsfiddle.net/UpjmU/
使用> :not()
选择器并在[target]
内部,选择所有没有target
属性.在第二种情况下,使用[ target ="pageContent" ]选择所有属性target
等于pageContent
using :not()
selector and inside [target]
, selects all a
that don't have a target
attribute. In the second case, using [target="pageContent"], selects all elements that the attribute target
equals pageContent
这篇关于jQuery-查找没有目标或特定目标的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!