zoukankan      html  css  js  c++  java
  • js实时获取input数据

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>on用onpropertychange,oninput事件解决onchange事件的不足 by koyoz.com</title>
    <style type="text/css">
    *{font-size:14px;font-family:'Comic Sans MS', Verdana}
    body {margin-left:20px}
    </style>
    </head>
    <body>
    <p>使用onchange事件: </p>
    <input type="text" id="txt1" />
    <p>使用onpropertychange/oninput事件: </p>
    <input type="text" id="txt2" />
    <p>结果:</p>
    <input type="text" id="txt" />

    <script type="text/javascript">
    var $ = function(o) {
    return document.getElementById(o)
    };
    $('txt1').onchange = function() {
    $('txt').value = this.value;
    }
    $('txt2').onpropertychange = function() {
    $('txt').value = this.value;
    }
    if (window.addEventListener) {
    $('txt2').addEventListener('input', function() {$('txt').value = this.value}, false);
    }
    </script>
    </body>
    </html>

    JQ:

    $("#textboxID").bind("propertychange", function() { 
    alert($(this).val()); 
    }); 

  • 相关阅读:
    4.12 IDEA 如何新建 Java 项目 (图文讲解, 良心教程)
    4.11 AndroidStudio快捷键总结
    4.9 Android AndroidX的迁移
    4.8 build.gradle中正确地导入RecyclerView依赖
    4.6 构建之法7
    4.5 构建之法6
    4.4 构建之法5
    4.3 构建之法4
    4.2 构建之法3
    4.1 构建之法2
  • 原文地址:https://www.cnblogs.com/kingreatwill/p/4012866.html
Copyright © 2011-2022 走看看