【发布时间】:2012-02-27 04:06:26
【问题描述】:
我正在尝试使用 .each() 检查所有锚点的标签,并将主页 URL 的目标设置为 _self,将其他非主页 URL 的目标设置为 _blank。
到目前为止,我得到了这个:
$('a').each(function() {
var homeURL = 'google.ca';
if ( $(this+'[href*='+homeURL+']')) {
$(this).attr('target','_self');
}else{
$(this).attr('target','_blank');
}
});
这也在 jsBin here.
由于某种原因,非主页 URL 设置为 target="_self"。谁能解释一下为什么?
【问题讨论】:
标签: jquery-selectors if-statement target jquery