执行JQuery脚本时页面滚动到顶部
本文关键字:滚动 顶部 JQuery 脚本 执行 | 更新日期: 2023-09-27 18:21:34
你能帮我吗?我做不到,这让我发疯了。
我在UpdatePanel中有一个GridView。gridview中的一个链接使用以下JQuery脚本:
ScriptManager.RegisterClientScriptBlock(this, GetType(), "Script1", "$('#divid1').click(function () {$('#divid2').toggle('slow');});", true);
所以我注册了这样的脚本,它运行良好。我遇到的问题是,每次我点击链接,页面都会滚动到顶部。如何在页面不滚动到顶部的情况下执行JQuery脚本onclick?
非常感谢!
如果href
属性中有#
,浏览器通常会跳到顶部。看看你是否有这个问题,并且你的代码在href
#
$('divid1').click(function (e) {
e.preventDefault();
// your other code
});
Because you are using `ScriptManager.RegisterClientScriptBlock ` this will go server side so scroll is going to top.
Instead of this use Jquery for link click event
$('divid1').click(function (e) {
e.preventDefault();
// your other code
});