Javascript/jQuery实时监听input输入框值变化

2018-09-19  本文已影响386人  Hi小胡

JQuery:

$("#input").bind("input propertychange",function(event){
       console.log($("#input").val())
});

Javascript:

<input type="text" oninput="show1(event)" onpropertychange="show2(event)" value="" />
<script type="text/javascript">
// Firefox, Google Chrome, Opera, Safari, Internet Explorer from version 9
function show1(event) {
    console.log(event.target.value);
}
// Internet Explorer
function show2(event) {
    if (event.propertyName.toLowerCase () == "value") {
        console.log(event.srcElement.value);
    }
}
</script>
上一篇下一篇

猜你喜欢

热点阅读