1. 程式人生 > >讓表單提交返回後保持在原來提交的位置上

讓表單提交返回後保持在原來提交的位置上

  1. <input type="submit" name="Button1" value="Button" id="Button1" />
  2. <input type="hidden" id="Window_OffsetY" name="Window_OffsetY" value="0">
  3. <input type="hidden" id="Window_OffsetX" name="Window_OffsetX" value="0">
  4. <script language="Javascript">
  5. var ua = navigator.userAgent.toLowerCase();
  6. var isIE = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) );
  7. function Window_OnSubmitIE(){
  8.     document.getElementById("Window_OffsetY").value = window.event.offsetY - window.event.clientY + 2;
  9.     document.getElementById("Window_OffsetX").value = window.event.offsetX - window.event.clientX + 2 ;
  10. }
  11. function Window_OnSubmitNS(event){
  12.     document.getElementById("Window_OffsetY").value = event.pageY - event.clientY;
  13.     document.getElementById("Window_OffsetX").value = event.pageX - event.clientX;
  14. }
  15. if (!isIE){
  16.     document.forms[0].addEventListener('submit',Window_OnSubmitNS, false);
  17. }
  18. else{
  19.     document.forms[0].attachEvent('onsubmit',Window_OnSubmitIE);
  20. }
  21. function Lili1_OnLoad(){
  22.     window.scrollTo(0,1431);
  23. }
  24. if (!isIE){
  25.     window.addEventListener('load',Lili1_OnLoad, false);
  26. }
  27. else{
  28.     window.attachEvent('onload',Lili1_OnLoad);
  29. }
  30. </script>