Cms技巧
分享创造价值 合作实现共赢

Cms技巧

当前位置: 首页 > 新闻动态 > Cms技巧

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

发布时间:2019-12-16 11:16:01作者:admin点击:

方法如下:

拷贝一个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")+"\"";

TOP

QQ客服

18910140161