Home >Web Front-end >JS Tutorial >Case study on jQuery solving browser compatibility issues_jquery
This article analyzes jQuery’s method of solving browser compatibility issues with examples. Share it with everyone for your reference, the details are as follows:
Question:
When the user presses the Enter key in the input control named abc, the click event of another control imgLogin is triggered
In IE document.getElementById('abc').click(); can call the click event of abc
But not in FF.
Solution:
Must look like this:
var evt = document.createEvent("MouseEvents"); evt.initEvent("click", true, true); document.getElementById("imgLogin").dispatchEvent(evt);
Only in order to execute the click event of the input control
If through JQuery.
$("#abc").keydown(function(e) { if (e.keyCode == 13) { $("#imgLogin").click(); } });
Just a few simple sentences are enough, there is no need to judge the browser
Readers who are interested in more jQuery-related content can check out the special topics on this site: "JQuery cookie operation skills summary", "jQuery table (table) operation skills summary" , "Summary of jQuery drag effects and techniques", "Summary of jQuery extension techniques", "Summary of jQuery common classic special effects", "jQuery animation and special effects usage summary", "jquery selector usage summary" and "jQuery common plug-ins and usage summary"
I hope this article will be helpful to everyone in jQuery programming.