如何使 jquery UI 滑块在回发时保持滚动位置
所以我在我的页面上实现了 Jquery UI 滑块。滑块的值作为参数输入到 SQL 数据源。单击按钮后,参数将被输入数据源,屏幕上的网格视图将重新绑定。问题是我希望滚动条保持其位置,以便用户知道输入了什么值作为他们当前正在查看的 gridview 的参数。
这是我的滚动条代码:
<!--Slider bar for investment-->
<div style="float:right;">
<script type = "text/javascript">
$(function () {
$("#slider").slider({
value: 100,
min: 1,
max: 200,
step: 1,
slide: function (event, ui) {
$("#hiddenInvestment").val(ui.value);
}
});
$("#hiddenInvestment").val($("#slider").slider("value"));
});
</script>
<div class="demo">
<p>
<asp:label runat="server" id="amountlabel" >Investment:
</asp:label>
<input name="hiddenInvestment" id="hiddenInvestment" />
<asp:Label runat="server" ID="percentlabel">%</asp:Label>
</p>
<div id="Div1"></div>
</div>
<div class="demo" style="width:100px;">
<div id="slider"></div>
</div>
我认为需要更改的行是“值:100”,但我不确定需要将其更改为什么。有什么建议吗?
So I'm implementing a the Jquery UI slider on my page. The value of the slider bar is fed in as a parameter to a sql datasource. On a button click, the parameter is fed into the datasource and the gridview on the screen rebinds. The problem is that I would like the scrollbar to maintain its position so that users know what value was fed in as a parameter for the gridview they are currently viewing.
Here is my code for the scrollbar:
<!--Slider bar for investment-->
<div style="float:right;">
<script type = "text/javascript">
$(function () {
$("#slider").slider({
value: 100,
min: 1,
max: 200,
step: 1,
slide: function (event, ui) {
$("#hiddenInvestment").val(ui.value);
}
});
$("#hiddenInvestment").val($("#slider").slider("value"));
});
</script>
<div class="demo">
<p>
<asp:label runat="server" id="amountlabel" >Investment:
</asp:label>
<input name="hiddenInvestment" id="hiddenInvestment" />
<asp:Label runat="server" ID="percentlabel">%</asp:Label>
</p>
<div id="Div1"></div>
</div>
<div class="demo" style="width:100px;">
<div id="slider"></div>
</div>
The line that I assume I need to alter is the 'value: 100', but I'm not sure what I need to change it to. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在页面上设置隐藏字段。在
提交
用于回发
的表单
之前,请使用slider
值设置此隐藏字段。在页面加载时,当您初始化slider
时,会从此隐藏
字段读取初始值。试试这个You can have a hidden field on the page. Before you
submit
theform
forpostback
set this hidden field withslider
value. On page load when you initialize theslider
read the initial value from thishidden
field. Try this