我的页面上有个treeview控件,我想维护滚动条的位置。
方法是:
给treeview所在的div一个onclick事件,将div的scrollTop保存在隐藏域里(runat="server"),
postback时再取出来赋给div.
<div id="treeDiv" style="width:100%;height:250px;overflow:scroll;" onclick="divClick();" >
<asp:TreeView ID="TreeView1" runat="server" Width="100%"
style="text-align:left;padding-left:30px;" ShowLines="True"
onselectednodechanged="TreeView1_SelectedNodeChanged"><SelectedNodeStyle BorderColor="#FF3300" BorderWidth="1px" />
<NodeStyle />
</asp:TreeView>
</div>
<input id="scrolltop" type="hidden" runat="server"/>
<script>
var treediv = document.getElementById("treeDiv");
function divClick(){
document.getElementById("scrolltop").value= treediv.scrollTop;
}
treediv.scrollTop = '100';//document.getElementById("scrolltop").value;
</script>文档添加了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
在ie8下可以正常看到效果,但在ie7下却不可以,我把DOCTYPE 删除以后,都不可以了,
咋办?
方法是:
给treeview所在的div一个onclick事件,将div的scrollTop保存在隐藏域里(runat="server"),
postback时再取出来赋给div.
<div id="treeDiv" style="width:100%;height:250px;overflow:scroll;" onclick="divClick();" >
<asp:TreeView ID="TreeView1" runat="server" Width="100%"
style="text-align:left;padding-left:30px;" ShowLines="True"
onselectednodechanged="TreeView1_SelectedNodeChanged"><SelectedNodeStyle BorderColor="#FF3300" BorderWidth="1px" />
<NodeStyle />
</asp:TreeView>
</div>
<input id="scrolltop" type="hidden" runat="server"/>
<script>
var treediv = document.getElementById("treeDiv");
function divClick(){
document.getElementById("scrolltop").value= treediv.scrollTop;
}
treediv.scrollTop = '100';//document.getElementById("scrolltop").value;
</script>文档添加了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
在ie8下可以正常看到效果,但在ie7下却不可以,我把DOCTYPE 删除以后,都不可以了,
咋办?
要把treediv.scrollTop = '100';//document.getElementById("scrolltop").value;
放在window.onload里,也就是说要等文档结构全部加载完毕才能对scrollTop 赋值,
不知道ie7怎么这么麻烦.
你的建议我试过了,不是那个原因