好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

html中用户(在键盘上)按键时触发的事件属性onkeypress

实例

当用户按键时执行一段 JavaScript:

<input type="text" onkeypress="displayResult()"> 

浏览器支持

IE

Firefox

Chrome

Safari

Opera

所有主流浏览器都支持 onkeypress 属性。

定义和用法

onkeypress 属性在用户(在键盘上)按键时触发。

提示:相对于 onkeypress 事件的事件次序:

onkeydown onkeypress onkeyup

注释:在任何浏览器中,onkeypress 事件不会被所有按键触发(例如 ALT、CTRL、SHIFT、ESC)。

注释:onkeypress 属性不适用以下元素:<base>、<bdo>、<br>、<head>、<html>、<iframe>、<meta>、<param>、<script>、<style> 或 <title>。

HTML 4.01 与 HTML5 之间的差异

无。

语法

<element onkeypress="script"> 

属性值

值 描述 script onkeypress 发生时运行的脚本。
<input class="text" type="text" name="PAGE" size="60" maxlength="2" value="<%=bg.getPAGE()%>" onkeypress="if(event.keyCode<48 || event.keyCode>57) event.returnValue=false;"> 

报错:

Multiple annotations found at this line:
- Invalid character used in text string (57) event.returnValue=false;">).
- Syntax error on token "||", ) expected
- Attribute value (if(event.keyCode<48 || ) not closed.
- Undefined attribute name (event.keyCode). 

把大于57放在前面就对了。。。亲试

以上就是html中用户(在键盘上)按键时触发的事件属性onkeypress的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于html中用户(在键盘上)按键时触发的事件属性onkeypress的详细内容...

  阅读:49次