Home >Web Front-end >JS Tutorial >Solution to the conflict between jquery and NVelocity_jquery

Solution to the conflict between jquery and NVelocity_jquery

WBOY
WBOYOriginal
2016-05-16 18:06:051005browse

There are several solutions when NVelocity's $ conflicts with Jquery's $:
1.
Use jQuery.noConflict. For example: var j = jQuery.noConflict(); j.ajax();
Disadvantage: When using jQuery related plug-ins, the plug-ins will become invalid!
2.
Use jQuery instead of $. Such as: jQuery.ajax();
Disadvantages: Not suitable for expansion. Once replaced with a third-party library, it will be troublesome
3.
wrap conflicting methods in jQuery.
If $.ajax() conflicts in Velocity, redefine it as follows:
function dw(){}
dw.ajax=function(s){ jQuery.ajax(s); } dw .ajax();
4.
Define a $JQ as $. You can use ${JQ}AJAX in js in the future.
Write (definition) like this at the front desk: #set($JQ="$.")
I recommend the fourth method.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn