input text onchange

    xiaoxiao2021-04-11  30

    <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 库的话,只需要同时绑定 oninput 和 onpropertychange 两个事件就可以了,示例代码如下:

    1 2 3 $( 'textarea' ).bind( 'input propertychange' ,  function () {      $( '.msg' ).html($( this ).val().length +  ' characters' ); });
    转载请注明原文地址: https://ju.6miu.com/read-666497.html

    最新回复(0)