Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to map the object referenced by $back to the original object in jQuery

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article Xiaobian introduces in detail "how to map the $referenced object back to the original object in jQuery" with detailed content, clear steps and proper handling of the details. I hope that this article "how to map the $referenced object back to the original object in jQuery" can help you solve your doubts.

We can release the jQuery name and pass true as an argument to this method. This is not necessary, and if we have to do this (for example, if we use multiple versions of the jQuery library on the same page), we must take into account that most plug-ins rely on variables that exist in jQuery, which may cause the plug-in to fail to operate properly.

Example:

Example: maps the object referenced by $back to the original object.

JQuery.noConflict ()

/ / Do something with jQuery

JQuery ("div p") .hide ()

/ / Do something with another library's $()

("content") .style.display = 'none'

Example: restore the alias $, and then create and execute a function that still uses $as the alias for jQuery in the scope of this function. In this function, the original $object is invalid. This function is very effective for most plug-ins that do not rely on other libraries.

JQuery.noConflict ()

(function ($) {

$(function () {)

/ / more code using $as alias to jQuery

})

}) (jQuery)

/ / other code using $as an alias to the other library

Example: you can constrain to a small piece of code through jQuery.noConflict () ready

Var j = jQuery.noConflict ()

/ / Do something with jQuery

J ("div p") .hide ()

/ / Do something with another library's $()

("content") .style.display = 'none'

Example: create a new alias to use the jQuery object in the following library.

Var dom = {}

Dom.query = jQuery.noConflict (true)

Result:

/ / Do something with the new jQuery

Dom.query ("div p") .hide ()

/ / Do something with another library's $()

("content") .style.display = 'none'

/ / Do something with another version of jQuery

JQuery (div > p) .hide ()

Example: Load two versions of jQuery (not recommended). Then, restore jQuery's globally scoped variables to the first loaded jQuery.

Before $.noConflict (true)

Var $log = $("# log")

$log.append ("2nd loaded jQuery version ($):" + $.fn.jquery + "

")

/ *

Restore globally scoped jQuery variables to the first version loaded

(the newer version)

* /

Jq162 = jQuery.noConflict (true)

$log.append ("After $.noConflict (true)")

$log.append ("1st loaded jQuery version ($):" + $.fn.jquery + "

")

$log.append ("2nd loaded jQuery version (jq162):" + jq162.fn.jquery + "

")

After reading this, the article "how to map the $referenced object back to the original object in jQuery" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it to understand it. If you want to know more about the article, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 229

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report