使用jquery防止默认行为 [英] prevent default behaviour using jquery

查看:82
本文介绍了使用jquery防止默认行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

hi i have a anchor tag but I want to prevent the default behaviour using jquery. But not getting the exact solution. can you tell me what is wrong in my code?


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


推荐答案

您错过了一个点:

eventpreventDefault();

应该是:

event.preventDefault();

如果你还可以使用 return false 希望禁用默认操作(转到指定链接)以及事件冒泡:

You can also use return false if you wish to disable default action (of going to specified link) as well as event bubbling:

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

这篇关于使用jquery防止默认行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆