简体   繁体   中英

Chrome onChange event not firing for cleared field after form reset

It seems that chrome is not firing a change event when a text field has been cleared just after the form has been reset.

Here is the code:

<html>
<head>
  <script>
    function doChange() {
      document.getElementById('info').innerHTML = 'Field changed to:[' + event.target.value + ']'; 
    }
  </script>
</head>
<body>
  <form>
    <input type='text' value='test1' onChange='doChange();'/>
    <input type='text' value='test2' onChange='doChange();'/>
    <button type='reset'>Reset</button>
    <div id='info'></div>
  </form>
</body>
</html>

See http://jsfiddle.net/ahc6fpuw/ for the test bed.

Is this a know issue and if so is does anyone have a work around?

Add steps to create the problem: 1 Enter some text into the first text field 2 Press the reset button (that resets the text correctly) 3 Select all the text in the first field and press the delete key 4 Press the tab key to move to the second text field. The doChange function should have been called but it is not.

重置为html元素提供默认值,在您的情况下为“ test1”和“ test2”,因此即使您重置,它也会显示“ test1”和“ test2”。

The reset button doesn't clears the text inside the form it just resets to given value. Try placeholder instead value attribute


<form>
    <input type='text' placeholder='test1' onChange='doChange();'/>
    <input type='text' placeholder='test2' onChange='doChange();'/>
    <button type='reset'>Reset</button>
    <div id='info'></div>
  </form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM