Article Source: http://www.zretc.com/technologyDetail/344.html
Once, in the era of the IE6 or mainstream browser, a lot of code is needed to achieve a slightly more complex feature. If you want to be compatible with mainstream browsers, it takes a lot of trouble. When jquery comes in, using jquery to do the same thing, we just need to write very little code and be compatible with mainstream browsers. As a result, most Web sites use JQuery.
In the end, do we need jQuery?
The reasons to think that jQuery is not needed are as follows:
· The market share of IE7 and the lower version of the browser is already low to the point of neglect. Using the native API of IE8 and later browsers to implement the functionality provided by JQuery is not a hassle. Like what:
/* Select element *///ie8+document.queryselectorall (selector);//jquery$ (selector);/* Ajax *///Ie8+var request = new (); Request.open (' G ET ', '/my/url ', true); Request.onreadystatechange = function () {if (this.readystate = = = 4) {if (This.status >= p;& This.status <) {//success! var resp = this.responsetext;} else {//Error:(}}}; Request.send (); request = null;//Jquery$.ajax ({type: ' GET ', url: '/my/url ', success:function (resp) {}, Error:function ( {}});/* Bind event *///ie8+function AddEventListener (el, EventName, handler) {if (El.addeventlistener) {El.addeventlistene R (EventName, handler); } else {el.attachevent (' on ' + eventName, function () {Handler.call (EL);});}} AddEventListener (EL, EventName, handler);//jquery$ (EL). On (EventName, EventHandler);
· The way to interact with JQuery is to select the DOM that corresponds to the data when the data changes, and then modify the DOM. If the HTML changes, such as the ID of an element is changed, and jquery uses the ID to find that element, the jquery code needs to be modified. And, if the page's data is complex to interact with the DOM, it's cumbersome to use JQuery. In these cases, the framework of MVVM is a good choice: the way that MVVM interacts with the page is to set the DOM's relationship with the data in HTML. The framework updates the DOM when the data changes.
Consider the need for jQuery for the following reasons
· JQuery has a rich library of plugins.
· Many modern frameworks rely on jQuery, such as Bootstrap JS plugin, Ember,meteor JS. If you want to use those frames, you have to use JQuery.
· Using JQuery is better than using native APIs to be studious, easy to use, powerful, concise, and does not need to consider browser compatibility issues.
· The development of JQuery is still ongoing. And the Times have added some new features. For example, the jquery 3 increase allows DOM elements to traverse the JQuery collection with the for ... of. Such as
var $inputs = $ (' input '), var i = 0;for (var input of $inputs) {input.id = ' input-' + i++;}
So, do we need jQuery in the end? In fact, according to the specific project to decide. For me, for the general project, I will use jquery, after all, jquery size is not small, for example, jquery-3.0.0-beta1.min.js before gzip compression also KB.
Software programming: Do we need jQuery in the end