因为美元符号$的原因导致了discuz x系统与jquery不兼容,解决方法如下:
Discuz X和jQuery的冲突有两点,在/include/javascript/common.js文件的57~64之间有如下代码:
Array.prototype.push = function(value) { this[this.length] = value; return this.length; } function $(id) { return document.getElementById(id); }
Discuz X为了兼容低版本的IE,重写了Array对象的push方法,但在重写之前没有做任何判断可以改为:
if(typeof Array.prototype.push === 'undefined') { Array.prototype.push = function(value) { this[this.length] = value; return this.length; } }
第二点就是Discuz X也有$()函数,就只是为了实现getElementById?功能没有人家强大就别学人家用美元符号嘛,占用符号资源。
关于$()函数的冲突,jQuery中给出了解决方法,jQuery.noConflict()改不用$符号。
jQuery代码可以这样写:
var jq = jQuery.noConflict(); //把$让给第一个实现它的库,用jq代替 jq(function() { //********************** } );
这样就完美解决了两者的冲突
转载请注明:Yovae Studio » discuz x与jquery不兼容问题