发布于 2016-11-02 23:15:56 | 93 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的jQuery示例,程序狗速度看过来!

jQuery javascript框架

jQuery是一个兼容多浏览器的javascript框架,核心理念是write less,do more(写得更少,做得更多)。jQuery在2006年1月由美国人John Resig在纽约的barcamp发布,吸引了来自世界各地的众多JavaScript高手加入,由Dave Methvin率领团队进行开发。


这篇文章主要介绍了transport.js和jquery冲突问题的解决方法,需要的朋友可以参考下

问题原因:/js/transport.js 文件
Object.prototype.toJSONString = function () {**************}
大概 580行到590行之间 这个句用于格式化json,他重写了object的结构,导致于js框架冲突,如果要解决需要把这段代码注释掉,然后用别的方式替换。

我是将所有用到*.toJSONString的地方,替换成一个函数,例如:
/js/common.js 29行
Ajax.call(‘flow.php?step=add_to_cart', ‘goods=' + goods.toJSONString, addToCartResponse, ‘POST', ‘JSON');

替换成:

Ajax.call(‘flow.php?step=add_to_cart', ‘goods=' + obj2str(goods), addToCartResponse, ‘POST', ‘JSON');
obj2str函数如下:


function obj2str(o){
var r = [];
if(typeof o ==”string”) return “\”"+o.replace(/([\'\"\\])/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)
r.push(“\”"+i+”\”"+”:”+obj2str(o[i]))
r=”{“+r.join()+”}”
}else{
for(var i =0;i<o.length;i++)
r.push(obj2str(o[i]))
r=”["+r.join()+"]”
}
return r;
}
return o.toString();
}

大概这样就可以了,可能还有些脚步错误需要处理,您自己体会下 , 这只是个解决方法,并不一定适用您的网站。

我注释了下面这一段


/*
Object.prototype.toJSONString = function () {
……
// Join all of the fragments together and return.

a.push(‘}');
return a.join(”);
};
*/


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务