【解决ecshop和jquery冲突】解决ecshop和jquery冲突 自定义美化商品属性选择

更新时间:2019-10-24    来源:jquery    手机版     字体:

【www.bbyears.com--jquery】

方法如下:

拷贝一个transport.js  为 transport1.js

在需要用到的页面插入这个新js

隐藏 586行处开始:
/*
 Object.prototype.toJSONString = function () {
 var a = ['{'], // The array holding the text fragments.
 b, // A boolean indicating that a comma is required.
 k, // The current key.
 v; // The current value.
 
function p(s) {
 
// p accumulates text fragment pairs in an array. It inserts a comma before all
 // except the first fragment pair.
 
if (b) {
 a.push(',');
 }
 a.push(k.toJSONString(), ':', s);
 b = true;
 }
 
// Iterate through all of the keys in the object, ignoring the proto chain.
 
for (k in this) {
 if (this.hasOwnProperty(k)) {
 v = this[k];
 switch (typeof v) {
 
// Values without a JSON representation are ignored.
 
case 'undefined':
 case 'function':
 case 'unknown':
 break;
 
// Serialize a JavaScript object value. Ignore objects that lack the
 // toJSONString method. Due to a specification error in ECMAScript,
 // typeof null is 'object', so watch out for that case.
 
case 'object':
 if (this !== window)
 {
 if (v) {
 if (typeof v.toJSONString === 'function') {
 p(v.toJSONString());
 }
 } else {
 p("null");
 }
 }
 break;
 default:
 p(v.toJSONString());
 }
 }
 }
 
// Join all of the fragments together and return.
 
a.push('}');
 return a.join('');
 };
*/

修改 common.js getSelectedAttributes方法。(如果需要的话)这里是解决商品商品属性点击的时候切换价格的
/**
 * 获得选定的商品属性
 */
function getSelectedAttributes(formBuy)
{
 var spec_arr = new Array();
 var j = 0;
 
for (i = 0; i < formBuy.elements.length; i ++ )
 {
 var prefix = formBuy.elements[i].name.substr(0, 5);
 
if (prefix == 'spec_' && (
 ((formBuy.elements[i].type == 'hidden' || formBuy.elements[i].type == 'checkbox') && formBuy.elements[i].checked) ||
 formBuy.elements[i].tagName == 'SELECT'))
 {
 spec_arr[j] = formBuy.elements[i].value;
 j++ ;
 }
 }
 
return spec_arr;
}

common.js 加入:

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 r.push(obj2str(o[i]))
 r="["+r.join()+"]"
 }
 return r;
 }
 return o.toString();
}

加入购物车改为:
Ajax.call('flow.php?step=add_to_cart', 'goods=' + obj2str(goods), addToCartResponse, 'POST', 'JSON');




一招解决!!!解决ECSHOP中transport.js和jquery的冲突

在page_header.lbi文件的最后面添加下面的代码即可,经IETester测试后,ie6及以上都可行。
{insert_scripts files='niuzai/jquery-1.8.3.js'}
<script type="text/javascript">
$(function() {
window.__Object_toJS**tring = Object.prototype.toJS**tring;
delete Object.prototype.toJS**tring;
});
</script>
{insert_scripts files='test.js'}

注:**为大写O-N-S,去掉中间的两个-,被屏蔽了,无语。先声明一下,这不是我自创的,而是看了论坛里的兄弟的相关帖子后,然后我试了没用,因为导入文件顺序的问题,导致不能解决,所以就发了这个帖子,和大家分享分享。test.js为自己用jquery写的一些代码,要放在jquery文件的后面,注意不能和jquery文件一同导入,注意顺序,否则会出错。顺序为:先导入transport.js文件{insert_scripts files='transport.js,utils.js'},然后导入jquery文件 ,{insert_scripts files='niuzai/jquery-1.8.3.js'} 再加上这段代码<script type="text/javascript">
$(function() {
window.__Object_toJS**tring = Object.prototype.toJS**tring;
delete Object.prototype.toJS**tring;
});
</script>
最后引入自己用jquery书写的js文件。{insert_scripts files='test.js'}

本文来源:http://www.bbyears.com/wangyezhizuo/75144.html