当用户单击指向外部源的链接时,我正在使用以下代码获取免责声明;两个JavaScript警报窗口
$(
function() {
$("a[href^='http://']:not([href*='"+location.hostname+"']), [href^='https://']:not([href*='"+location.hostname+"'])")
.attr("target","_blank")
.click(function(e) {
alert('My message here');
});
});
哪些工作,但我需要添加第二个消息,当一个特定的链接点击。我试着添加if和else语句(下面的例子),但这不起作用。我是否使用正确的方法,如果还是应该尝试不同的路线?
$(
function() {
$(if "a[href^='http://']:not([href*='"+location.hostname+"']), [href^='https://']:not([href*='"+location.hostname+"'])")
.attr("target","_blank")
.click (function(e) {
alert('My original message here');
});
(else if
"a[href^='http://theurlhere'")
.attr("target","_blank")
.click (function(e) {
alert('Test');
});
});
'(否则if'这是随机的,请看看一些文档 – 2014-09-10 09:00:52
'if'是一个声明,而不是表达 – elclanrs 2014-09-10 09:00:57