0%

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

JQ版本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!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>

JS版本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!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>