input 输入框实时监听输入内容

js实现

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
   <input type="text" id="input" oninput="aa(event)" onporpertychange="aa(event)">
   <script type="text/javascript">
   var input = document.getElementById('input'); 
    function aa(e){
      console.log(input.value);
    }
   </script>
</body>
</html>

jquery:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
</head>
<body>
   <input type="text" id="input" >
  <script type="text/javascript">

     $(function(){
        $('input').bind('input porpertychange',function(){
            console.log($(this).val());
        });
     })
   </script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/zhongshijun521/article/details/76677104
今日推荐