在作web開發時候不少時候都須要即時監聽輸入框值的變化,以便做出即時動做去引導瀏覽者加強網站的用戶體驗感。而採用onchange時間又每每是在輸入框失去焦點(onblur)時候觸發,有時候並不能知足條件。javascript
首先看一下dom中元素事件:java
$("#input1").bind("input propertychange change",function(event){ console.log($("#input1").val()) });
<script type="text/javascript"> // Firefox, Google Chrome, Opera, Safari, Internet Explorer from version 9 function OnInput (event) { alert ("The new content: " + event.target.value); } // Internet Explorer function OnPropChanged (event) { if (event.propertyName.toLowerCase () == "value") { alert ("The new content: " + event.srcElement.value); } } </script> //Input標籤 <input type="text" oninput="OnInput (event)" onpropertychange="OnPropChanged (event)" value="Text field" />
轉: https://blog.csdn.net/idomyway/article/details/79078625jquery