$(
'#username'
).bind(
'input propertychange'
,
function
() {
$(
'#content'
).html($(
this
).val().length +
' characters'
);
});
从上面表格能够看出,oninput 事件在 IE9 如下版本不支持,须要使用 IE 特有的 onpropertychange 事件替代,这个事件在用户界面改变或者使用脚本直接修改内容两种状况下都会触发,有如下几种状况:javascript
在监听到 onpropertychange 事件后,能够使用 event 的 propertyName 属性来获取发生变化的属性名称。html
集合 oninput & onpropertychange 监听输入框内容变化的示例代码以下:java
<head>
<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> </head> <body> Please modify the contents of the text field. <input type="text" oninput="OnInput (event)" onpropertychange="OnPropChanged (event)" value="Text field" /> </body> |