ecshop和jquery冲突问题
发布:smiling 来源: PHP粉丝网 添加日期:2014-06-19 14:24:48 浏览: 评论:0
主要就是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_x_x_x("DIV");
- var submitBtn = document_createElement_x_x_x_x("INPUT");
- this.compareList = document_createElement_x_x_x_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.a(this.compareList);
- this.compareBox.a(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.a(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_x_x_x("LI");
- var span = document_createElement_x_x_x_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.a(span);
- li.style.listStyle = "none";
- var delBtn = document_createElement_x_x_x_x("IMG");
- delBtn.src = "themes/default/images/drop.gif";
- delBtn.className = key;
- delBtn.onclick = function(){
- document.getElementByIdx_x_xx_xx_x("compareList").removeChild(this.parentNode);
- delete self.data[this.className];
- self.save();
- self.init();
- }
- li.insertBefore(delBtn,li.childNodes[0]);
- this.compareList.a(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_xx_xx_x(domid).style.top=parseInt(document.getElementByIdx_x_xx_xx_x(domid).style.top)+percent+"px";
- lastScrollY=lastScrollY+percent;
- //alert(lastScrollY);
- }
Tags: ecshop jquery冲突
- 上一篇:怎么优化ECshpo,从哪方面入手
- 下一篇:ecshop 用户名邮箱手机号码登录
相关文章
- ·ECshop在线客服代码添加操作(2013-11-15)
- ·ecshop2.7.0商品分类显示数量(2013-11-15)
- ·Ecshop与jQuery冲突最简单的解决办法! (2013-11-15)
- ·ecshop不同的文章分类使用不同的模板的方法(2013-11-15)
- ·使用.htaccess来实现ecshop 301重定向的方法(伪静态可行)(2013-11-15)
- ·本机安装Ecshop时出现创建管理员帐号失败(2013-11-30)
- ·ecshop分类树显示所有分类的解决方法(2013-12-02)
- ·ecshop后台登录超时session过期的解决办法(2013-12-07)
- ·Ecshop系统添加免运费赠品后购物车变为收取运费解决办法(2014-01-06)
- ·将ecshop相对地址改成绝对地址的方法(2014-01-10)
- ·ECShop——回到顶部(2014-01-10)
- ·ECShop 模板修改(2014-01-10)
- ·Ecshop与jQuery冲突最简单的解决办法(2014-06-13)
- ·ecshop后台登录地址修改(2014-06-14)
- ·ecshop商城回收站的设计(2014-06-14)
- ·ecshop的标题$page_title之seo优化方案(2014-06-14)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)