The discussion on an issue of mootools on github is very interesting, so I want to test it. Interested can click the original page to see https://github.com/mootools/mootools-core/issues/2170
This problem comes from the implementation problem of checkbox and radio change events in IE (LTE8). Test it in IE (LTE8). When you click a checkbox or radio, the change event is not triggered immediately, unless you make it lose focus, and in other standard browsers (including IE9), the change event is triggered immediately after the click, this is indeed a problem. When it comes to the solution, it is easier to handle it with the propertychange event unique to the element in IE (LTE8) (IE9 is no longer a problem ), the above problems can be avoided, such:
The Code is as follows:
CheckEl. attachEvent ('onpropertychang', function (){
Console. log ('Hey man, I am changed ');
});
However, this solution is not sufficient because it is similar to checkEl. operations such as setAttribute ('data-value', 'God') will also trigger the propertychange event, so we need to use its event. propertyName to determine, such:
The Code is as follows:
CheckEl. attachEvent ('onpropertychang', function (){
If (window. event. propertyName = 'checked ')
Console. log ('H H blah ...');
});
This is acceptable. As a result, I tested the select statement again. The change event is consistent in different browsers, and there is no need to lose focus first. I tested the input [type = "text"] again. The change event is familiar to us and will be triggered only when the focus is lost, so when we want it to be triggered immediately as soon as we input something, refer to the previous example in IE (LTE8), we can use propertychange to implement it, only the propertyName condition becomes 'value. In other standard browsers (including IE9), we can use a standard event input in HTML5, such:
The Code is as follows:
InputEl. addEventListener ('inputel, function (event ){
Console. log ('input event fired ');
}, False );
In this way, every input will trigger this event. Some people will say why keyup is not used for listening. Here is an article (the original article link) that explains this issue, you can also read it if you are interested.