2011-01-29 103 views
2

您好我有一个锚标记,但我想防止使用jQuery的默认行为。但没有得到确切的解决方案。你能告诉我我的代码有什么问题吗?防止默认行为使用jquery

 
$(document).ready(function(){ 
    $("a[name]").click(function(event){ 
    alert("As you can see, the link no longer took you to jquery.com"); 
    eventpreventDefault(); 
    }); 
}); 

回答

4

你缺少点:

eventpreventDefault(); 

应该是:

event.preventDefault(); 

您也可以使用return false如果您希望禁用默认操作(要去指定的链接)作为以及事件冒泡:

$(document).ready(function(){ 
    $("a[name]").click(function(event){ 
    alert("As you can see, the link no longer took you to jquery.com"); 
    return false; 
    }); 
}); 
+0

o对不起,我真是太傻了。谢谢 – newdeveloper 2011-01-29 13:07:12