主要就是Ecshop的AJAX传输类,transport.js中重写了object的对象原型,从而导致了与jq框架的冲突。

解决:

1. 删除transport.js中587行 - 636行中关于object.prototype.toJSONString的定义

2. 自定义一个方法用于object对象的json序列化

如下

function obj2str(o)

{

//开始

var r = [];

if(typeof o =="string") return "\""+o.replace(/([\'\")/g,]\\])/g,"\\$1").replace(/(\n)/g,"\\n").replace(/(\r)/g,"\\r").replace(/(\t)/g,"\\t")+"\"";

if(typeof o =="undefined") return "undefined";

if(typeof o == "object"){

if(o===null) return "null";

else if(!o.sort){

for(var i in o)

{

if(i!="toJSONString") //增加判断,清除对object原型的定义加入到json中

r.push("\""+i+"\""+":"+obj2str(o));

}

r="{"+r.join()+"}";

}else{

for(var i =0;i<o.length;i++)

r.push(obj2str(o))

r="["+r.join()+"]"

}

return r;

}

return o.toString();

//结束

}

3. 在模板页和js脚本中所有对于obj.toJSONString()的地方,一概替换为obj2str(obj)

4. 重写好后发现compare.js, 主要重写其中的定时器功能。 将以下代码替换到compare.js中

var Compare = new Object();

Compare = {

add : function(goodsId, goodsName, type)

{

var count = 0;

for (var k in this.data)

{

if (typeof(this.data[k]) == "function")

continue;

if (this.data[k].t != type) {

alert(goods_type_different.replace("%s", goodsName));

return;

}

count++;

}

if (this.data[goodsId])

{

alert(exist.replace("%s",goodsName));

return;

}

else

{

this.data[goodsId] = {n:goodsName,t:type};

}

this.save();

this.init();

},

init : function(){

this.data = new Object();

var cookieValue = document.getCookie("compareItems");

if (cookieValue != null) {

this.data = cookieValue.parseJSON();

}

if (!this.compareBox)

{

this.compareBox = document.createElement_x("DIV");

var submitBtn = document.createElement_x("INPUT");

this.compareList = document.createElement_x("UL");

this.compareBox.id = "compareBox";

this.compareBox.style.display = "none";

this.compareBox.style.top = "200px";

this.compareBox.align = "center";

this.compareList.id = "compareList";

submitBtn.type = "button";

submitBtn.value = button_compare;

this.compareBox.appendChild(this.compareList);

this.compareBox.appendChild(submitBtn);

submitBtn.onclick = function() {

var cookieValue = document.getCookie("compareItems");

var obj = cookieValue.parseJSON();

var url = document.location.href;

url = url.substring(0,url.lastIndexOf('/')+1) + "compare.php";

var i = 0;

for(var k in obj)

{

if(typeof(obj[k])=="function")

continue;

if(i==0)

url += "?goods[]=" + k;

else

url += "&goods[]=" + k;

i++;

}

if(i<2)

{

alert(compare_no_goods);

return ;

}

document.location.href = url;

}

document.body.appendChild(this.compareBox);

}

this.compareList.innerHTML = "";

var self = this;

for (var key in this.data)

{

if(typeof(this.data[key]) == "function")

continue;

var li = document.createElement_x("LI");

var span = document.createElement_x("SPAN");

span.style.overflow = "hidden";

span.style.width = "100px";

span.style.height = "20px";

span.style.display = "block";

span.innerHTML = this.data[key].n;

li.appendChild(span);

li.style.listStyle = "none";

var delBtn = document.createElement_x("IMG");

delBtn.src = "themes/default/images/drop.gif";

delBtn.className = key;

delBtn.onclick = function(){

document.getElementByIdx_x("compareList").removeChild(this.parentNode);

delete self.data[this.className];

self.save();

self.init();

}

li.insertBefore(delBtn,li.childNodes[0]);

this.compareList.appendChild(li);

}

if (this.compareList.childNodes.length > 0)

{

this.compareBox.style.display = "";

this.timer = window.setInterval("flowdiv('compareBox')", 50);

}

else

{

this.compareBox.style.display = "none";

window.clearInterval(this.timer);

this.timer = 0;

}

},

save : function()

{

var date = new Date();

date.setTime(date.getTime() + 99999999);

document.setCookie("compareItems", obj2str(this.data));

},

lastScrollY : 0

}

//用于定时器的自动滚动的层

lastScrollY=0;

function flowdiv(domid){

   var diffY;

    if (document.documentElement && document.documentElement.scrollTop)

      diffY = document.documentElement.scrollTop;

    else if (document.body)

      diffY = document.body.scrollTop

    else

      {}

    //alert(diffY);

    percent=.1*(diffY-lastScrollY);

    if(percent>0) percent=Math.ceil(percent);

    else percent=Math.floor(percent);

    document.getElementByIdx_x(domid).style.top=parseInt(document.getElementByIdx_x(domid).style.top)+percent+"px";

    lastScrollY=lastScrollY+percent;

    //alert(lastScrollY);

}

如何全面解决ECSHOP的jquery冲突的更多相关文章

  1. Ecshop与Jquery冲突的完美解决方案

    ecshop把AJAX事件和JSON解析的模块放在common/transport.js之中,可以说它也有自己封装的一套工具,这其实是很正常的.   但恰恰的,在封装JSON各种方法的同时对objec ...

  2. ecshop和jQuery冲突

    这个问题看ecshop的论坛里有很多帖子,解决方案就好几种,但是有几个标注完美解决方案的需要更改很多文件,对于我们这种初学者出现了问题的话是不知道怎么调试的. 找到一个很简单的解决方案,论坛里说只能解 ...

  3. ecshop之transport和jquery冲突之完美解决方案

    众所周知:ecshop的transport.js文件和Jquery是冲突的,两个文件不能同时调用,现给出以下完美解决方案:原因分析:在transport.js文件中,大概 580行到590行之间,这个 ...

  4. 关于ecshop中jquery与js冲突解决的方案

    ECShop把AJAX事件和JSON解析的模块放在common/transport.js之中,可以说它也有自己封装的一套工具,这其实是很正常的.   但恰恰的,在封装JSON各种方法的同时对objec ...

  5. Discuz!和jQuery冲突的解决办法

    Common.js是官方自带的,我没改过它,所以不可能出错,所以问题就应该是两者冲突了.导致的结果我也发现了,前台的DIY功能不能用了.   我还花了很多时间在那里研究冲突的地方,后来还是没能解决.之 ...

  6. discuz教程:discuz模板js与jQuery冲突的解决方案

    今天在做discuz模板的时候,用到jquery的时候和原来主题js冲突.这个主要是Discuz X使用了$(id)作为dom节点的获取方法,而$符号刚好与jQuery的默认符号相冲突. 以下是基于之 ...

  7. jquery冲突

    今天修改一个项目发现,前辈们自己写的一些方法和jquery冲突了,也就是$的冲突,以至于自己用jquery编写的新功能无法正常使用,细究后发现解决办法如下:使用 noConflict() 方法为 jQ ...

  8. JQuery冲突问题,以及含有jquery的框架与jquery冲突

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. 解决Ecshop因为动态ip问题登录后台自动退出

    解决Ecshop因为动态ip问题登录后台自动退出 PHP  铁匠  2年前 (2013-07-21)  1130℃  0评论 修改lib_base.php文件real_ip()函数,添加以下代码即可解 ...

随机推荐

  1. js面向对象的使用方法

    标准用法: function Sprite(){ //函数内容部设置属性 this.name='shimily'; } //原型上设置方法 Sprite.prototype.show=function ...

  2. DataTable数据导出CSV文件

    public static void SaveAsExcel(DataTable dt1) { //System.Windows.Forms.SaveFileDialog sfd = new Syst ...

  3. js调用.net后台事件、后台调用前台以及js调用服务器控件

    1. javaScript函数中执行C#代码中的函数: 方法一:间接触发后台代码 1.首先建立一个服务端控件按钮命名为btn1,双击进入后台将调用或处理的内容写入btn1_click中; 2.在前台写 ...

  4. centos 6安装epel

    1.通过:https://mirrors.ustc.edu.cn/找到epel rpm包链接,这里的是 https://mirrors.ustc.edu.cn/epel/epel-release-la ...

  5. [并查集] POJ 1703 Find them, Catch them

    Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43132   Accepted: ...

  6. Visual Studio 2015 新建MVC项目 Package Manager Console不能使用 (HRESULT: 0x80131500)

    Visual studio 2015 突然新建不了MVC项目,报出错误: HRESULT: 0x80131500 在折腾了很长时间,最后在Github上看到这样一个贴 地址:https://githu ...

  7. java多线程之 基本概念

    一.线程的五种状态 1. 新建状态(New)         : 线程对象被创建后,就进入了新建状态.例如,Thread thread = new Thread().2. 就绪状态(Runnable) ...

  8. vi技巧合集

    VIM 技巧 match & replace match the whole word(eg: match printf but not snprintf/fprintf)You can us ...

  9. 个人对sort()排序方法中比较函数一直很混乱,今日理清

    需求:使用随机数来打印出0-10,并排序. 代码: var a = new Array();var testArray = function() { while (1) { var b = parse ...

  10. hibernate的一种报错

    Exception in thread "main" java.lang.NoClassDefFoundError: javax/tools/StandardJavaFileMan ...