jquery有input事件,jquery實作input輸入框即時輸入觸發事件碼是「$('#productName').bind('input propertychange', function() {...}”。
jquery有input事件嗎?
有。<input id="productName" name="productName" class="wid10" type="text" value="" />
//绑定商品名称联想 $('#productName').bind('input propertychange', function() {searchProductClassbyName();});
$('#username').bind('input propertychange', function() { $('#content').html($(this).val().length + ' characters'); });
修改了input:text 或textarea 元素的值,value 屬性改變。 修改了 select 元素的選取項,selectedIndex 屬性改變。 在監聽到 onpropertychange 事件後,可以使用 event 的 propertyName 屬性來取得變化的屬性名稱。 集合 oninput & onpropertychange 監聽輸入框內容變化的範例程式碼如下:
<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>
以上是jquery有input事件嗎的詳細內容。更多資訊請關注PHP中文網其他相關文章!