使用jQuery的animate(),如果单击的元素为“ ”,该函数是否仍应返回false?

我正在阅读jQuery的animate()页面

http://api.jquery.com/animate/

它的示例没有提及是否使用

<a href="#" id="clickme">click me</a>
...

$('#clickme').click(function() {
    $('#someDiv').animate({left: "+=60"});
})

我们实际上仍然必须像过去一样返回false?

$('#clickme').click(function() {
    $('#someDiv').animate({left: "+=60"});
    return false;
})

(但随后,这些示例并未将< a>用于“点击我” …而是使用了其他内容.

否则,页面将跳回到页面的开头? jQuery有更优雅或更神奇的方式吗?

最佳答案
您需要使用event.preventDefault()

$('...').click(function(event) {
    event.preventDefault();
    // Code.
});

jQuery Website

event.preventDefault()
Description:
If this method is called,the default
action of the event will not be
triggered.

相关文章

1.第一步 设置响应头 header(&#39;Access-Control-Allow...
$.inArray()方法介绍 $.inArray()函数用于在数组中搜索指定的...
jquery.serializejson.min.js的妙用 关于这个jquery.seriali...
JS 将form表单数据快速转化为object对象(json对象) jaymou...
jQuery插件之jquery.spinner数字智能增减插件 参考地址:http...