[英]How to alert with jQuery when a link is clicked?
我想在点击<a>
提醒一些事情,但<a>
是有一个真正的链接。 我有这个代码,但它并没有真正起作用...
$("a").click(function(){
if ($(this).attr("href") != "#" && $(this).attr("href") != "") {
alert("foo");
}
});
怎么了?
谢谢
确保您在方法中调用e.preventDefault()
。
$("a").click(function(e){
if ($(this).attr("href") != "#" && $(this).attr("href") != "") {
alert("foo");
e.preventDefault();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.