您的位置:58编程 > HTML事件属性onkeyup

HTML事件属性onkeyup

2023-05-01 07:33 HTML参考手册

 HTML事件属性onkeyup

HTML事件属性onkeyup


触发 onkeyup 属性事件当用户按下一个键。

与onkeydown事件相关的事件顺序:

  • onkeydown
  • onkeypress
  • onkeyup


HTML5中的新功能

没有。

句法

<element onkeyup="script or Javascrpt function name">

支持的标签

所有HTML元素,EXCEPT:

<base>, 
<bdo>, 
<br>, 
<head>, 
<html>, 
<iframe>, 
<meta>, 
<param>, 
<script>, 
<style>, 
<title>


浏览器兼容性

onkeyup Yes Yes Yes Yes Yes

例子

<!DOCTYPE html>
<html>
<body>

<input type="text" onkeyup="myFunction()">

<script>
function myFunction() {
    console.log("pressed a key");
}
</script>

</body>
</html>

Click to view the demo

实施例2

在JavaScript中监听TextArea的键向上事件

<html>
<head>
<script type="text/javascript">
  function handleEvent(oEvent) {
    var oTextbox = document.getElementById("txt1");
    oTextbox.value += "n>" + oEvent.type;
  }
</script>
</head>
<body>
  <P>Type some characters into the first textbox.</p>
  <P>
    <textarea id="txtInput" rows="15" cols="50"
      onkeydown="handleEvent(event)" onkeyup="handleEvent(event)"
      onkeypress="handleEvent(event)"></textarea>
  </p>
  <P>
    <textarea id="txt1" rows="15" cols="50"></textarea>
  </p>
</body>
</html>

Click to view the demo

阅读全文
以上是58编程为你收集整理的 HTML事件属性onkeyup全部内容。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。
相关文章
© 2024 58编程 58biancheng.com 版权所有 联系我们
桂ICP备12005667号-32 Powered by CMS