Home > Article > Web Front-end > jQuery custom method of adding "$" and resolving "$" conflict_jquery
The example in this article describes how to customize jQuery to add "$" and resolve "$" conflicts. Share it with everyone for your reference. The specific analysis is as follows:
1. Customize adding $
Although jQuery is very powerful, in any case, jQuery cannot meet the needs of all users, and some needs are very niche and are not suitable for inclusion in the entire jQuery framework. It is precisely because of this that jQuery provides users with Customize the method of adding "$".
The code is as follows:
Then use an anonymous function to define this method, that is, use each() to set the disabled attribute of each element that calls this method to true. (If this attribute exists)
Example: Extending the functions of jquery
The method SwapInput(nName,oButton) judges based on the value of the button. If it is not available "disable", then dispatch disable() to set the element to be unavailable, and at the same time modify the value of the button to "enable", otherwise it will dispatch enable() method.
2. Resolve the conflict of "$"
Similar to the situation in the previous article, although JQuery is very powerful, sometimes developers use multiple frameworks at the same time. At this time, you need to be careful, because other frameworks may also use "$", resulting in conflicts. jQ also provides noConflict () method to solve the problem of "$" conflict.
I hope this article will be helpful to everyone’s jQuery programming.