",该函数仍然应该返回 false 吗?-6ren"> ",该函数仍然应该返回 false 吗?-我正在阅读 jQuery 的 animate() 页面 http://api.jquery.com/animate/ 它的示例没有提及 if using click me ... $('#clickm-6ren">
gpt4 book ai didi

jquery - 使用 jQuery 的 animate(),如果点击的元素是 " ",该函数仍然应该返回 false 吗?

转载 作者:行者123 更新时间:2023-12-01 01:20:20 25 4
gpt4 key购买 nike

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

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

它的示例没有提及 if using

<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.

关于jquery - 使用 jQuery 的 animate(),如果点击的元素是 "<a href="#"...> </a>",该函数仍然应该返回 false 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3042036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com