[英]How to prevent this code from affecting img onclick?
$(document).ready(function(){
$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target","_blank");
$("a[target!='_blank'][target!='_top']").live('click', function(){
$("#actualcontent").html('<center><img src="/deltasite/uploads/smallloader.gif"></center>');
var url=$(this).attr("href")+'?jquery=1';
$("#actualcontent").load(url);
$("#nav").load('/delta/pack_files/other/nav.php?url=' +$(this).attr("href"));
window.location.hash=$(this).attr("href");
return false;
});
});
由于某种原因,在网站的一个嵌入式页面上,这似乎会影响具有onclick属性的链接和图像。 知道为什么吗? (即使目标是空白或顶部)。 似乎只在一页上烦人。
有任何想法吗?
谢谢,汤姆。
尝试使用:not
选择器和has属性选择器的组合排除具有onclick
属性的图像/链接:
$("a[href*='http://']:not([href='foo']):not([onclick])").attr("target","_blank");
演示: http : //jsfiddle.net/HjYEX/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.