我使用以下代码在ASP.NET Web应用程序中创建滚动div。
{
{ "usage.accounting.values" : { $all : [ "knowledgetest", "feedback"] } },
{ "usage.anothercategory.values" : { $all [ "knowledgetest", "assessment" ] } }
}
但每当我向下滚动并点击任何单选按钮或复选框时,滚动就会转到顶部,我必须再次向下滚动。每次我点击表单上的内容时都会发生这种情况。有没有办法阻止它,并且每当我与表单交互时都不会将滚动移动到默认的顶部位置?
<div id="my_scroll_form" style="overflow:auto; height:500px">
//My large form goes here (contains radio buttons and check boxes)
</div>
&#13;
以上是HTML中的工作片段,但如果单击单选按钮,则此处的卷轴不会重置。在我的情况下,我使用带有<div id="request_scroll" style="overflow:auto; height:100px">
<input type="radio" name="select" value="option1" /> Option 1 <br />
<input type="radio" name="select" value="option2" /> Option 2 <br />
<input type="radio" name="select" value="option3" /> Option 3 <br />
<input type="radio" name="select" value="option4" /> Option 4 <br />
<input type="radio" name="select" value="option5" /> Option 5 <br />
<input type="radio" name="select" value="option6" /> Option 6 <br />
<input type="radio" name="select" value="option7" /> Option 7 <br />
<input type="radio" name="select" value="option8" /> Option 8 <br />
<input type="radio" name="select" value="option9" /> Option 9 <br />
<input type="radio" name="select" value="option10" /> Option 10 <br />
</div>
的ASP.NET Web表单,我的后端代码是C#,处理此radiobutton列表的<asp:RadioButtonList>
事件。当我单击ASP.NET窗体中的单选按钮时滚动重置到最高位置。
答案 0 :(得分:0)
使用此代码。
Javascript
代码:
<script type="text/javascript">
window.onload = function () {
var div = document.getElementById("request_scroll");
var div_position = document.getElementById("div_position");
var position = parseInt('<%=Request.Form["div_position"] %>');
if (isNaN(position)) {
position = 0;
}
div.scrollTop = position;
div.onscroll = function () {
div_position.value = div.scrollTop;
};
};
</script>
Asp.Net
代码:
<div id="my_scroll_form" style="overflow:auto; height:500px;text-align:center">
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<div id="request_scroll" style="overflow-y:scroll; height:100px;">
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="lbl" Text="radio1" AutoPostBack="true" OnCheckedChanged="RadioButton1_CheckedChanged" /><br />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="lbl" Text="radio2" AutoPostBack="true" OnCheckedChanged="RadioButton2_CheckedChanged"/><br />
<asp:RadioButton ID="RadioButton8" runat="server" GroupName="lbl" Text="radio3" AutoPostBack="true" OnCheckedChanged="RadioButton8_CheckedChanged"/><br />
<asp:RadioButton ID="RadioButton7" runat="server" GroupName="lbl" Text="radio4" AutoPostBack="true" OnCheckedChanged="RadioButton7_CheckedChanged"/><br />
<asp:RadioButton ID="RadioButton6" runat="server" GroupName="lbl" Text="radio5" AutoPostBack="true" OnCheckedChanged="RadioButton6_CheckedChanged"/><br />
<asp:RadioButton ID="RadioButton5" runat="server" GroupName="lbl" Text="radio6" AutoPostBack="true" OnCheckedChanged="RadioButton5_CheckedChanged"/><br />
<asp:RadioButton ID="RadioButton9" runat="server" GroupName="lbl" Text="radio7" AutoPostBack="true" OnCheckedChanged="RadioButton9_CheckedChanged"/><br />
<asp:RadioButton ID="RadioButton4" runat="server" GroupName="lbl" Text="radio8" AutoPostBack="true" OnCheckedChanged="RadioButton4_CheckedChanged"/><br />
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="lbl" Text="radio9" AutoPostBack="true" OnCheckedChanged="RadioButton3_CheckedChanged"/><br />
<asp:RadioButton ID="RadioButton10" runat="server" GroupName="lbl" Text="radio10" AutoPostBack="true" OnCheckedChanged="RadioButton10_CheckedChanged"/><br />
</div>
</div>
<input type="hidden" id="div_position" name="div_position" />