Upgrade from jQuery 1.x to jQuery 2.x

后端 未结 3 1293
清歌不尽
清歌不尽 2021-01-30 20:09

I am trying to upgrade from jQuery 1.x to jQuery 2.x.

I have jQuery 1.8 and jQueryUI 1.8, and now I want to upgrade to jQuery 2.x and enhance my web app.

So m

3条回答
  •  一生所求
    2021-01-30 21:02

    1. Do not use offset option in position properties, e.g. code $element.position({my: 'center center', at: 'center center', offset: '5 -10'}) should be replaced with $element.position({my: 'center center', at: 'center+5 center-10'}).
    2. Do not use $element.bind(), $element.live(), $element.delegate() to assign event handler, use $element.on().
    3. Do not use browser sniffing with $.browser, try to use feature detection instead ($.support).
    4. Do not use deferred.isRejected(), deferred.isResolved(), use deferred.state() instead. Do not use deferred.pipe(), the deferred.then() method should be used instead.
    5. Do not use the $elements.size() method, use the $elements.length property instead. The .size() method is functionally equivalent to the .length property; however, the .length property is preferred because it does not have the overhead of a function call.
    6. Checkbox/radio state in a .trigger()ed "click" event now has the same state as in a user-initiated action.
    7. Changed naming convention for .data() keys, e.g., ui-dialog instead of dialog. (http://jqueryui.com/upgrade-guide/1.9/#changed-naming-convention-for-data-keys).
    8. Do not use $.ui.contains(), use $.contains() instead.
    9. Each widget instance already has unique identifier this.uuid and event namespace this.eventNamespace = "." + this.widgetName + this.uuid. Do not generate similar things manually.
    10. Do not use $element.focus(n) - it is deprecated. Use setTimeout(function() { $element.focus(); }, n);.
    11. Do not use $element.zIndex() - it is deprecated.
    12. Do not use $.ui.keyCode.NUMPAD_* constants - they are removed.
    13. Do not use $element.data('someWidget') to retrieve widget instance. Use instance() method: $element.someWidget('instance'). Unlike other plugin methods, the instance() method is safe to call on any element. If the element is not an instance of the given widget, the method returns undefined: $('
      ').dialog('instance') /* returns undefined instead of throwing Error */
      .

    Original upgrade guides and full list of changes:

    • jQuery Core 1.9 Upgrade Guide
    • jQuery UI 1.9 Upgrade Guide
    • jQuery UI 1.10 Upgrade Guide
    • jQuery UI 1.11 Upgrade Guide
    • jQuery UI 1.12 Upgrade Guide

提交回复
热议问题