This article is mainly about the onchange event in IE and FF performance and solutions are introduced, the need for friends can come to the reference, I hope to help you.
In a recent project, there is a function point: there is a checkbox on the page that sends a JSONP request to the background when the user chooses or cancels the checkbox. The implementation was for this checkbox to add a onchange event, but the result is unexpected, for this reason, I studied in depth, found that the onchange event in IE and FF under the performance of the following problems. ①: Under FF, when the checkbox is selected, the onchange event is triggered immediately. However, when changing the checkbox's selected state in IE, it does not start onchange events immediately, but waits for the Checbox to lose focus before the event starts. To solve this problem, I added the This.blur () statement to the checkbox's OnClick event because the onclick event was executed before the onchange event and therefore added This.blur in the onclick event () causes the checkbox to lose focus and immediately departs onchange event. In this way, a second problem has been encountered. Problem ②: When the onclick event and This.blur are used at the same time, the error will be in IE. looked up some information on the Internet and finally found the Onpropertychange event. This event is not triggered under FF. In IE, when the checkbox's selection state changes, it will start immediately. Thus, the final solution is obtained: under IE, the checkbox is bound to the Onpropertychange event, and under FF, the onchange event is bound to it. Specific code implementation is as follows: code as follows: Var ua=navigator.useragent.tolowercase (); var s=null; var browser={ MSIE: (S=ua.match/msies* ([D.] +)/)? S[1]:false, Firefox: (S=ua.match (/firefox/) ([D.] +)/)? S[1]:false Chrome: (S=ua.match (/chrome/) ([D.] +)/)? S[1]:false, Opera: (S=ua.match (/opera). ( [D.] +)/))? S[1]:false, &nbsP Safari: (S=ua.match (/varsion/) ([D.] +). S[1]:false }; if (Browser.msie) {//For IE browser checkbox.onpropertychange=function *safari/)? () { //do someting } else{ checkbox.onchange=function () {&N Bsp //do something }}