To celebrate jQuery's fourth anniversary, the official jQuery team officially released jQuery 1.4 . In this version, the jQuery official team has done a lot of coding, testing and documentation work. It has naturally improved a lot compared to the previous version. Let’s take a look at the new changes.
This article is divided into two parts. The first part mainly introduces the related uses and updates of jQuery 1.4 version. The second part uses some code examples to show the updated methods and newly added methods.
【Download and call】
As usual, the official provides two copies of jQuery, one is a compressed version (compressed using Google Closure Compiler , previously using YUI), and the other is an uncompressed version (used for debugging and reading).
It has been previously proposed to load jQuery through the Google server to improve loading speed . Now, we can still call the compressed jQuery 1.4 version file through Google's server, as follows:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"><!--mce:0--></script >
【New features and changes 】
In jQuery 1.4, many commonly used jQuery methods have been rewritten. These improvements are not only easier to use, but also bring significant improvements in performance.
Note: The following is an overview, please refer to the code explanation in the next article for any unknown details.
1. Add Setter Functions to some methods
In previous versions, we could pass a function to the attr() method and assign the return value of the function to an attribute. In 1.4, this functionality was added to more methods: .css(), .attr(), .val(), .html(), .text(), .append(), .prepend(), . before(), .after(), .replaceWith(), .wrap(), .wrapInner(), .offset(), .addClass(), .removeClass(), .toggleClass().
In addition, in the following methods, you can also pass in the current value as the second parameter of the setting function for use by the setting function: .css(), .attr(), .val(), .html(), .text( ), .append(), .prepend(), .offset(), .addClass(), .removeClass(), and .toggleClass(). For example:
jQuery('<img src="enter.png" alt="enter your name" />')
.attr("alt", function(index, value) {
return "Please, " + value;
});
2. Updated the core method of serialization in jQuery, jQuery.param()
Previously, the serialized result for {foo: ["bar", "baz"]} was "foo=bar&foo=baz", but now it is "foo[]=bar&foo[]=baz".
The purpose of this change is mainly to tell the receiving end that what is passed in is an array object.
3. In jQuery.ajax , when the dataType attribute is not specified, it will be automatically identified based on the content-type of the response.
For example: if the object returned by the ajax request is of json type (application/json), the dataType will be automatically specified as "json" (if not specified).
4. Add support for Etag in jQuery.ajax request.
Previously, jQuery did not send the If-None-Match value in the header in the ajax request (that is, it did not support Etag), and the browser cache was ignored by default. It can now be enabled by specifying the ifModified attribute.
Tip: If you don’t know about http headers, it is recommended to read this article .