php专区

 首页 > php专区 > PHP应用 > CMS建站 > ecshop和jquery冲突问题 - ecshop

ecshop和jquery冲突问题 - ecshop

分享到:
【字体:
导读:
          主要就是Ecshop的AJAX传输类,transport js中重写了object的对象原型,从而导致了与jq框架的冲突 解决:1 删除transport js中587行 - 636行中关于object prototype toJSONString的定义2 自定义一个...

ecshop和jquery冲突问题

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

解决:

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

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

  1. function obj2str(o) 
  2.   //开始 
  3.       var r = []; 
  4.    if(typeof o =="string"return """+o.replace(/(['")/g,]\])/g,"\$1").replace(/(n)/g,"\n").replace(/(r)/g,"\r").replace(/(t)/g,"\t")+"""
  5.    if(typeof o =="undefined"return "undefined"
  6.    if(typeof o == "object"){    
  7.     if(o===nullreturn "null"
  8.     else if(!o.sort){ 
  9.      for(var i in o) 
  10.      {   
  11.       if(i!="toJSONString"//增加判断,清除对object原型的定义加入到json中 
  12.       r.push("""+i+"""+":"+obj2str(o)); 
  13.      } 
  14.      r="{"+r.join()+"}"
  15.     }else
  16.      for(var i =0;i
  17.       r.push(obj2str(o)) 
  18.      r="["+r.join()+"]" 
  19.     } 
  20.     return r; 
  21.    } 
  22.    return o.toString(); 
  23.   //结束    

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

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

  1. var Compare = new Object(); 
  2. Compare = { 
  3.   add : function(goodsId, goodsName, type) 
  4.   { 
  5.     var count = 0; 
  6.     for (var k in this.data) 
  7.     { 
  8.       if (typeof(this.data[k]) == "function"
  9.       continue
  10.       if (this.data[k].t != type) { 
  11.         alert(goods_type_different.replace("%s", goodsName)); 
  12.         return
  13.       } 
  14.       count++; 
  15.     } 
  16.     if (this.data[goodsId]) 
  17.     { 
  18.       alert(exist.replace("%s",goodsName)); 
  19.       return
  20.     } 
  21.     else 
  22.     { 
  23.       this.data[goodsId] = {n:goodsName,t:type}; 
  24.     } 
  25.     this.save(); 
  26.     this.init(); 
  27.   }, 
  28.   init : function(){ 
  29.     this.data = new Object(); 
  30.     var cookieValue = document.getCookie("compareItems"); 
  31.     if (cookieValue != null) { 
  32.       this.data = cookieValue.parseJSON(); 
  33.     } 
  34.     if (!this.compareBox) 
  35.     { 
  36.       this.compareBox = document_createElement_x_x_x_x("DIV"); 
  37.       var submitBtn = document_createElement_x_x_x_x("INPUT"); 
  38.       this.compareList = document_createElement_x_x_x_x("UL"); 
  39.       this.compareBox.id = "compareBox"
  40.       this.compareBox.style.display = "none"
  41.       this.compareBox.style.top = "200px"
  42.       this.compareBox.align = "center"
  43.       this.compareList.id = "compareList"
  44.       submitBtn.type = "button"
  45.       submitBtn.value = button_compare; 
  46.    this.compareBox.a(this.compareList); 
  47.       this.compareBox.a(submitBtn); 
  48.       submitBtn.onclick = function() { 
  49.         var cookieValue = document.getCookie("compareItems"); 
  50.         var obj = cookieValue.parseJSON(); 
  51.         var url = document.location.href; 
  52.         url = url.substring(0,url.lastIndexOf('/')+1) + "compare.php"
  53.         var i = 0; 
  54.         for(var k in obj) 
  55.         { 
  56.           if(typeof(obj[k])=="function"
  57.           continue
  58.           if(i==0) 
  59.             url += "?goods[]=" + k; 
  60.           else 
  61.             url += "&goods[]=" + k; 
  62.           i++; 
  63.         } 
  64.         if(i<2) 
  65.         { 
  66.           alert(compare_no_goods); 
  67.           return ; 
  68.         } 
  69.         document.location.href = url; 
  70.       } 
  71.       document.body.a(this.compareBox); 
  72.     } 
  73.     this.compareList.innerHTML = ""
  74.     var self = this
  75.     for (var key in this.data) 
  76.     { 
  77.       if(typeof(this.data[key]) == "function"
  78.         continue
  79.       var li = document_createElement_x_x_x_x("LI"); 
  80.       var span = document_createElement_x_x_x_x("SPAN"); 
  81.       span.style.overflow = "hidden"
  82.       span.style.width = "100px"
  83.       span.style.height = "20px"
  84.       span.style.display = "block"
  85.       span.innerHTML = this.data[key].n; 
  86.       li.a(span); 
  87.       li.style.listStyle = "none"
  88.       var delBtn = document_createElement_x_x_x_x("IMG"); 
  89.       delBtn.src = "themes/default/images/drop.gif"
  90.       delBtn.className = key; 
  91.       delBtn.onclick = function(){ 
  92.         document.getElementByIdx_x_xx_xx_x("compareList").removeChild(this.parentNode); 
  93.         delete self.data[this.className]; 
  94.         self.save(); 
  95.         self.init(); 
  96.       } 
  97.       li.insertBefore(delBtn,li.childNodes[0]); 
  98.       this.compareList.a(li); 
  99.     } 
  100.     if (this.compareList.childNodes.length > 0) 
  101.     { 
  102.       this.compareBox.style.display = ""
  103.       this.timer = window.setInterval("flowdiv('compareBox')", 50); 
  104.     } 
  105.     else 
  106.     { 
  107.       this.compareBox.style.display = "none"
  108.       window.clearInterval(this.timer); 
  109.       this.timer = 0; 
  110.     } 
  111.   }, 
  112.   save : function() 
  113.   { 
  114.     var date = new Date(); 
  115.     date.setTime(date.getTime() + 99999999); 
  116.     document.setCookie("compareItems", obj2str(this.data)); 
  117.   }, 
  118.   lastScrollY : 0 
  119. //用于定时器的自动滚动的层 
  120. lastScrollY=0; 
  121. function flowdiv(domid){ 
  122.    var diffY; 
  123.     if (document.documentElement && document.documentElement.scrollTop) 
  124.       diffY = document.documentElement.scrollTop; 
  125.     else if (document.body) 
  126.       diffY = document.body.scrollTop 
  127.     else 
  128.       {} 
  129.     //alert(diffY); 
  130.     percent=.1*(diffY-lastScrollY); 
  131.     if(percent>0) percent=Math.ceil(percent); 
  132.     else percent=Math.floor(percent); 
  133.     document.getElementByIdx_x_xx_xx_x(domid).style.top=parseInt(document.getElementByIdx_x_xx_xx_x(domid).style.top)+percent+"px"
  134.     lastScrollY=lastScrollY+percent; 
  135.     //alert(lastScrollY); 
  136.  
分享到:
ecshop 用户名邮箱手机号码登录 - ecshop
ecshop 用户名邮箱手机号码登录 1.将原来的登录代码: if ($user->login($username, $password,isset($_POST[&#039;remember&#039;])))          {              update_user_info();              recalculate_price();        ...
怎么优化ECshpo,从哪方面入手 - ecshop
怎么优化ECshpo,从哪方面入手 一、完全自定义页面titile,完全抛弃Ecshop定义的页面title格式:[产品名称]_[分类名]_[网店名称] 1,分析:大家都知道,titile,kewords,description在SEO中的基础性和重要性,但是ECshop官方给出的titile实现方法会出现很多类似或相同的页面title,另外还有部分页...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……