<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>

<p>该实例演示了如何使用 addEventListener() 方法向 input 元素中添加 "oninput" 事件。</p>
<p>向文本框中尝试输入即可触发事件。</p>
输入您的名字: <input type="text" id="myInput" value="Mickey">
<script>
document.getElementById("myInput").addEventListener("input", myFunction);
function myFunction() {
    alert("input 输入框值已发生变化。");
}
</script>

</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>

<p>该实例演示了如何使用 HTML DOM 向 input 元素中添加 "oninput" 事件。</p>
<p>向文本框中尝试输入即可触发事件。</p>
输入您的名字:  <input type="text" id="myInput" value="Mickey">
<script>
document.getElementById("myInput").oninput = function() {myFunction()};
function myFunction() {
    alert("input 输入框值已发生变化。");
}
</script>

</body>
</html>

 

感谢菜鸟教程runoob.com

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-01
  • 2021-10-13
  • 2021-05-30
  • 2021-09-07
相关资源
相似解决方案