在asp.net中如何截获backspace按键:
如果用户按了backspace键,可以刷新网页(refresh)

解决方案 »

  1.   


         function backspace()
    {
      if (event.keyCode == 8 && event.srcElement.tagName != "INPUT" && event.srcElement.type != "text")
          event.returnValue=false;
    }
    这样行么
      

  2.   

    <html>
    <head>
    <script>
     function document.onkeypress(){  
        if (event.keyCode == 8)
      {
        event.returnValue=false;
        event.cancel = true;
        window.location.href='当前页面.aspx';
            //window.location.reload();
      }
      }
    </script>
    </head>
    <body>
    </body>
    </html>
      

  3.   

    修改为这样,2楼的不能捕获backspace.
    <html>
    <head>
    <script>
     function keydown(){  
        if (event.keyCode == 8)
      {
        event.returnValue=false;
        event.cancel = true;
        window.location.href='a.html';
            //window.location.reload();
      }
      }
    </script>
    </head>
    <body onkeydown="keydown();">
    </body>
    </html>
      

  4.   

    请问楼上function document.onkeypress()函数要在哪里调用它,如何调用
      

  5.   

    function document.onkeypress()这样就已经被调用了。
    不要写成这样了,这样捕获不到退格,只能捕获字母回车之类的消息。
    用3楼的写法。
      

  6.   

    这个肯定是前台aspx文件里捕获的,写在后台效率太低,用3楼的方法不行也就出奇了,不会照着做都做错了吧?
    <html>
    <head>
    //head里写的
    <script>
     function keydown(){  
        if (event.keyCode == 8)
      {
        event.returnValue=false;
        event.cancel = true;
        window.location.href='a.html';//修改为你要跳转的url
            //window.location.reload();
      }
      }
    </script>
    </head>
    <body onkeydown="keydown();">//加了吗?
    </body>
    </html>这个我测试通过的,LZ再仔细好好看看。
      

  7.   

    <body onkeydown="keydown();">//加了吗? 
    ......
    如何body里有一个函数调用例如:
    <body id="bottomBody" onload="MM_preloadImages('images/tabImg1Off.gif','images/tabImg2On.gif')" onkeydown="keydown();">
    这样可以吗,按所用键都没进入,在onkeydown函数里我加了一句window.alert("ok");没有弹出
      

  8.   

    看看页面上是不是有js错误,把onload="MM_preloadImages('images/tabImg1Off.gif','images/tabImg2On.gif')"去了试下,看是不是这个影响了。
    我给你的那段代码是正确的,我这里测试通过,你仔细检查一下,应该是你的页面里有问题。
    或者把onkeydown换成onkeypress,onkeyup试试。
      

  9.   

    编译没出现错误,但点击Error List 窗口显示很多错误,例如:
    Error:Another object on this page already uses ID 'mainframe'.
    Error:Validation (XHTML 1.0 Transitional): The values permitted for this attribute do not include 'absmiddle'.
    Error:Validation (XHTML 1.0 Transitional): This name contains uppercase characters, which is not allowed.

      

  10.   

    呵呵,LZ慢慢调吧,意思是说id=mainframe的标签重复了。