jquery upgrade step on the pit road

Source: Internet
Author: User
Tags deprecated

    • 1. Deprecated attributes are used jQuery.browser

JQuery, starting with version 1.9, removed $.browser and $.browser.version and replaced it with $.support. In the updated version 2.0, IE 6/7/8 will no longer be supported. Later, if the user needs to support IE 6/7/8, only jQuery 1.9 can be used. If you want to fully support IE and mix jQuery 1.9 and 2.0, the official solution is:

<!-- [If Lt IE 9]>    <script src= ' jquery-1.9.0.js ' ></script><![ ENDIF]-<!--[if GTE IE 9]>    <script src= ' jquery-2.0.0.js ' ></ script><! [EndIf]  -

In front-end development, we often have to make different processing according to different browser versions, which jQuery.browser are used to extract browser-related information through the UserAgent field of the browser. It is deprecated in the new version, but it is recommended to use the method of feature detection and give a MODERNIZR library as a recommendation. However, change to this library may change the cost is a bit large, if you still want to follow jQuery.browser the idea, you can implement it yourself. For example:

$.browser.mozilla =/firefox/=/webkit/=/opera/=/msie/.test ( Navigator.userAgent.toLowerCase ());

The expression after the equal sign returns the True/false, which can be used directly to replace the original $.browser.msie .

Check if it is IE6:

//  Old if ($.browser.msie && 7 > $.browser.version) {} // New if typeof (Document.body.style.maxHeight)) {}

Check if it is IE 6-8:

if (!$.support.leadingwhitespace) {}
    • 2. The deprecated Live () method is used

Workaround: Use the On () method, $ (selector). On (event,childselector,data,function,map)

Parameters Describe
Event Necessary. Specifies one or more events or namespaces to remove from the selected element.

Multiple event values are separated by a space. Must be a valid event.
Childselector Optional. Specifies that event handlers can be added only to the specified child elements (and not to the selector itself, such as the deprecated Delegate () method).
Data Optional. Specifies additional data that is passed to the function.
function Optional. Specifies the function to run when an event occurs.
Map Specifies the event map ({event:function, event:function, ...})that contains one or more events to add to the element, and the function to run when the event occurs.

    • 3. jQuery.fn.attr incorrect use of the method

The correct way to use:

// gets the value that the input form now enters // set values for input form inputs

Meet an update one, record the pit history.

jquery upgrade step on the pit road

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.