javascript - Resetting a form in IE8 causes select input to fire 4 change events when value hasn't been modified -
i'm working following code:
<form id="myform"> <select name="myselect" id="myselect"> <option value="0">default</option> <option value="1">option 1</option> <option value="2" selected>option 2</option> <option value="3">option 3</option> </select> <input type="submit" value="go"> <input type="reset" class="reset" value="reset form"> </form> var $element = $('#myselect'); // save current value of element $element.data('oldval', $element.val()); // changes in value $element.on("change propertychange keyup input paste", function () { // if value has changed... (selects don't play nice -- if they've changed have have changed, though) if ($element.data('oldval') != $element.val() || $element.is('select')) { console.log("old value:", $element.data('oldval')); console.log("new value:", $element.val()); // updated stored value $element.data('oldval', $element.val()); } });
here's jsfiddle: http://jsfiddle.net/hzkn5/8/
if view under ie8 , click 'reset form' no other actions bunch of events hit console log:
this weird because select's value hasn't been modified @ all. not occur under latest chrome or firefox.
i wondering -- why on earth seeing value change many times? there way detect real select value changes?
so turns out in ie8 firing propertychanged event twice whenever form reset, doesn't fire actual change events. so, if listen -- should ok :)
Comments
Post a Comment