想刷新后,控制x轴滚动条和y轴滚动条的位置都不动,请问该怎么做呢?
我现在url里传的x、和y的坐标:
" <a name= 'sort ' onclick= 'this.href = this.href+\ "&xValue=\ "+(event.x+document.body.scrollLeft)+\ "&yValue=\ "+(event.y+document.body.scrollTop); ');
-----------------------
然后再获取到值:
<script>
String.prototype.getQueryString = function(name)
{
var reg = new RegExp( "(^|&|\\?) "+ name + "=([^&]*)(&|$) ");
var r = this.match(reg);
if (r!=null) return unescape(r[2]);
return null;
}
function getcoorxy(){
var coorx = window.location.href.getQueryString( "xValue ");
var coory = window.location.href.getQueryString( "yValue ");
if (coorx!=null) window.scrollTo(coorx,coory);
} </script>
------------------------------
这么写以后,我的问题是:我对第一列进行排序操作以后它停留的位置就沿x轴往右滚动一点,对第二列进行排序操作以后它停留的位置就沿x轴往右滚动两点,现在想做的是滚动轴不动,请问该怎么做呢?大家帮帮我啊!先谢过了!
------解决方案--------------------原理很简单,回发页面时记录 scrollTop 和 scrollLeft 值,
页面加载时重新设置这两个值即可。
注:俺用 ASP.NET + JS 实现过此功能。
------解决方案--------------------试下
parseInt(event.y)+parseInt(document.body.scrollTop)
排序是对table吗?那可以不用刷新的
------解决方案--------------------event.x的问题,因为鼠标点链接不能保证每次都点的是同一个位置,所以有偏差.
其实这里的event.x没什么作用啊,可以去掉
<script>
String.prototype.getQueryString = function(name)
{
var reg = new RegExp( "(^|&|\\?) "+ name + "=([^&]*)(&|$) ");
var r = this.match(reg);
if (r!=null) return unescape(r[2]);
return null;
}
function getcoorxy(){
if(window.location.href.toString().indexOf( "xValue ")!=-1){
var coorx = decodeURIComponent(window.location.href).getQueryString( "xValue ");
var coory = decodeURIComponent(window.location.href).getQueryString( "yValue ");
if (coorx!=null) window.scrollTo(coorx,coory);
}
} </script>
<body onload=getcoorxy()>
<br>
<br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br>
<br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br>
<br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br>
<a href= "# " style= "height:100 " onclick= 'document.location.href = document.URL+ "?xValue= "+(document.body.scrollLeft)+ "&yValue= "+(document.body.scrollTop); '> asdasd </a>
<br> <br> <br> dddd <br> <br> <br> <br> <br> <br> <br> <br>
<br> <br> <br> &l