仅当ctrl+;使用jquery单击按钮
我对jquery还是新手,这是我的代码(我把它放在html中) 这是在我的html中:仅当ctrl+;使用jquery单击按钮,jquery,html,Jquery,Html,我对jquery还是新手,这是我的代码(我把它放在html中) 这是在我的html中: <form method="GET"> <button>Submit</button> </form> <div class="test">Hello</div> 提交 你好 我单击按钮后,它不会滚动页面。 只有在按住ctrl键并单击按钮时,页面才会滚动 我错过什么了吗? 我目前正在使用jquery 2.1.4版,更具体地
<form method="GET">
<button>Submit</button>
</form>
<div class="test">Hello</div>
提交
你好
我单击按钮后,它不会滚动页面。
只有在按住ctrl键并单击按钮时,页面才会滚动
我错过什么了吗?
我目前正在使用jquery 2.1.4版,更具体地说,是在按钮中使用id
<button id='scroll'>Submit</button>
或者我不知道jQuery2.1.4是否支持这种新方法
$(document).on('click','#scroll',function(){
$('body,html').animate({
scrollTop : 0
}, 500);
});
希望这对您有所帮助您没有设置div的高度,而且您的按钮应该有type=“button”。请参见jquery 2.1.4
试试这个scrollTop:$(“.test”).position().topi已经发现了一个问题,因为我把按钮放在了标记中,所以它没有滚动。我可以知道jquery使用的最新版本是什么吗jquery 3.2.1@wumBo_
$('#scroll').click(function){
$('body,html').animate({
scrollTop : 0
}, 500);
});
$(document).on('click','#scroll',function(){
$('body,html').animate({
scrollTop : 0
}, 500);
});
'http://plnkr.co/edit/mFCGoLZ4BCLRSpGTDzYk?p=preview'