zoukankan      html  css  js  c++  java
  • JavaScript 使用HTML DOM的oninput事件,实时监听value值变化

    <!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

  • 相关阅读:
    访问者模式
    解释器模式
    享元模式
    职责链模式
    中介者模式
    单例模式
    桥接模式
    命令模式
    迭代器模式
    Python 学习笔记15 类
  • 原文地址:https://www.cnblogs.com/pangpanghuan/p/6525053.html
Copyright © 2011-2022 走看看