1

你能帮帮我吗?无法让这个工作,它让我发疯。

我在 UpdatePanel 中有一个 GridView。gridview 中的链接之一使用以下 JQuery 脚本:

ScriptManager.RegisterClientScriptBlock(this, GetType(), "Script1", "$('#divid1').click(function () {$('#divid2').toggle('slow');});", true);

所以我正在注册这样的脚本,它工作正常。我遇到的问题是每次单击链接时,页面都会滚动到顶部。如何在页面不滚动到顶部的情况下执行 JQuery 脚本 onclick?

非常感谢!

4

3 回答 3

1

如果您#href属性中有浏览器通常会跳转到顶部。看看你是否有这个问题并且你的代码有一个#in href

于 2013-07-07T10:59:32.880 回答
0
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
});
于 2013-07-08T10:11:11.407 回答
0
$('divid1').click(function (e) {
    e.preventDefault();
    // your other code
});
于 2013-07-07T11:20:34.457 回答