相关疑难解决方法(0)

什么是JavaScript KeyCodes?

JavaScript可以使用哪些密钥代码?如果它们对于所有浏览器都不相同,请列出每个浏览器的密钥代码.

javascript keycode

82
推荐指数
5
解决办法
11万
查看次数

onKeyPress事件在Firefox中不起作用

我有以下javascript代码...这里我在body标签中使用onKeyPress ="someFunction()"来获取按下的键的keyCode.

代码在IE8中工作正常,但这在Firefox中不起作用.

请给出一些解决方案.

<html>
<head>
<title>onKeyPress( ) event not working in firefox..</title>
<script>
function printDiv()
{
  var divToPrint=document.getElementById('prnt');
  newWin=window.open(''+self.location,'PrintWin','left=50,top=20,width=590,height=840,toolbar=1,resizable=1,scrollbars=yes');
  newWin.document.write(divToPrint.outerHTML);
  newWin.print();
  //newWin.close();
}
</script>

<script>
function keypress()
{
  alert(event.keyCode);
  var key=event.keyCode;
  if(key==112 || key==80)
 printDiv();
  else if(key==101 || key==69)
    window.location="http://google.com";
  else if(key==114 || key==82)
    window.reset();  
}
</script>
</head>
<body bgcolor="lightblue" onkeypress="keypress()">
Run Code Online (Sandbox Code Playgroud)

提前致谢.....


这是在IE8中工作正常但在Firefox中无法正常工作的总代码.

<!DOCTYPE html>
<html>
    <head>
    <title>Please help me out</title>
    <script type="text/javascript">
    function printDiv()
    {
      var divToPrint=document.getElementById('prnt');
      newWin=window.open(''+self.location,'PrintWin','left=50,top=20,width=590,height=840,toolbar=1,resizable=1,scrollbars=yes');
      newWin.document.write(divToPrint.outerHTML);
      newWin.print();
    }
    </script>

    <script type="text/javascript">
    function …
Run Code Online (Sandbox Code Playgroud)

javascript firefox javascript-events onkeypress

9
推荐指数
3
解决办法
5万
查看次数

如何在按下美元键时找出按键或按键事件时按下的键

下面的方法返回来自AZ和0-9的任何键,当我按下shift键+ 4时,它返回相同的代码52.

function keyUpEvent(e)//onkeyup event
{
    var chr = String.fromCharCode(e.keyCode);//converts the keycode into a character
    alert(chr);//alerts the character
}
Run Code Online (Sandbox Code Playgroud)

但是当按下shift键组合的相应键时,我需要显示$或%.

javascript jquery keypress onkeyup

3
推荐指数
1
解决办法
2万
查看次数