如何防止此代码影响img onclick?

时间:2010-09-05 21:15:58

标签: javascript jquery html dynamic hyperlink

$(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属性的链接和图像。知道为什么吗? (即使他们的目标是空白或顶部)。它似乎只是在一页上做了,令人讨厌。

有什么想法吗?

谢谢, 汤姆。

1 个答案:

答案 0 :(得分:0)

尝试使用:not选择器和has attribute选择器的组合排除具有onclick属性的图片/链接:

$("a[href*='http://']:not([href='foo']):not([onclick])").attr("target","_blank");

演示:http://jsfiddle.net/HjYEX/2/

相关问题