使用jQuery的animate(),如果点击的元素是“< a href =”#“ ...> < / a>“,该函数应该仍然返回false? [英] Using jQuery's animate(), if the clicked on element is "<a href="#" ...> </a>", the function should still return false?
问题描述
我正在阅读jQuery的页面for animate()
http://api.jquery.com/animate/
其示例不提及如果使用
< a href =#id =clickme>点击我< / a>
...
$('#clickme')点击(function(){
$('#someDiv')。animate({left:+ = 60 });
})
我们实际上仍然需要像旧的天啊?
$('#clickme')点击(function(){
$('#someDiv' ).animate({left:+ = 60});
return false;
})
(但是,这些示例没有使用< a>
为点击我...但使用其他东西。 / p>
否则页面将跳回到页面的开头?jQuery是否有更优雅或神奇的方式?
您需要使用 event.preventDefault( ):
$('...')点击(function(event){
event.preventDefault();
//代码
});
从 jQuery网站:
event.preventDefault()
描述:
如果调用此方法,事件的默认
操作将不会被
触发。
I was reading jQuery's page for animate()
http://api.jquery.com/animate/
Its examples don't mention about if using
<a href="#" id="clickme">click me</a>
...
$('#clickme').click(function() {
$('#someDiv').animate({left: "+=60"});
})
we actually still have to return false like in the old days?
$('#clickme').click(function() {
$('#someDiv').animate({left: "+=60"});
return false;
})
(but then, those examples didn't use a <a>
for the "click me"... but used something else.
Otherwise the page will jump back to the beginning of the page? Does jQuery have a more elegant or magical way of doing it?
You need to use event.preventDefault():
$('...').click(function(event) {
event.preventDefault();
// Code.
});
From the jQuery Website:
event.preventDefault()
Description: If this method is called, the default action of the event will not be triggered.
这篇关于使用jQuery的animate(),如果点击的元素是“< a href =”#“ ...> < / a>“,该函数应该仍然返回false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!