Home  >  Article  >  Web Front-end  >  Case study on jQuery solving browser compatibility issues_jquery

Case study on jQuery solving browser compatibility issues_jquery

WBOY
WBOYOriginal
2016-05-16 15:05:281212browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn