onpropertychange 属IE
oninput 属除IE外(Chrome、Firefox、SS)
所以肯简单的办法嘛:
1. 一个input里面写两个属性事件
2.写在JS中判断浏览器添加监听事件
<script type="text/javascript"> function immediately() { element = document.getElementById("mytext"); if (window.ActiveXObject) { element.onpropertychange = webChange; } else { element.addEventListener("input", webChange, false); } } function webChange() { if (element.value) { document.getElementById("test").innerHTML = element.value; } ; } </script> Input: <input type="text" name="textfield" oninput="document.getElementById('webtest').innerHTML=this.value;" onpropertychange="document.getElementById('webtest').innerHTML=this.value;" /> <div>您输入的值为:<span id="webtest"></span></div> <br /><br /><br /><br /><br /> JS: <input type="text" name="textfield" id="mytext" /> <div>您输入的值为:<span id="test"></span></div> <script type="text/javascript"> immediately(); </script>
效果: