JS Real-time monitoring input value changeCategory: Javascript2014-05-11 11:13 849 people read comments (0) favorite reports
[HTML]View Plaincopyprint?
- <! DOCTYPE HTML>
- <html>
- <head>
- <meta http-equiv= "content-type" content= "text/html; Charset=utf-8 ">
- <title>runjs</title>
- <script id="jquery_183" type="Text/javascript" class= "Library" src="/js /sandbox/jquery/jquery-1.8.3.min.js "></script>
- </head>
- <body>
- <H1 >
- Real-time monitoring of changes in input values
- </H1>
- <input type="text" id="username" autocomplete=' off '>
- <div id="result"></div>
- </Body>
- </html>
[JavaScript]View Plaincopyprint?
- $ (function () {
- $ (' #username '). Bind (' input propertychange ', function () {
- $ (' #result '). HTML ($ (this). Val (). length + ' characters ');
- });
- })
Similar to the use of the ' can input xxx characters ' oninput,onpropertychange,onchange in the implementation of Weibo
onchangeThe triggering event must meet two conditions: a) The current object property is changed and is fired by a keyboard or mouse event (Invalid script trigger) b) The current object loses focus (onblur);
Onpropertychange, the event is triggered whenever the current object property is changed, but it is exclusive to IE;
OninputOnpropertychange is a non-IE browser version that supports browsers such as Firefox and Opera, but a little different when it's bound to an object, not all property changes in that object can trigger events, it only works if the object's value changes.
JS Real-time monitoring input value change