ecshop 和 jquery 冲突,美化商品属性选择

这个问题做了两遍了。。

这次一定要发上来,省得一直找问题。

拷贝一个transport.js  为 transport1.js

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

隐藏 586行处开始:

[code lang=”js”]

/*
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(”);
};
*/

[/code]

修改 common.js getSelectedAttributes方法。(如果需要的话)这里是解决商品商品属性点击的时候切换价格的

[code lang=”js”]

/**
* 获得选定的商品属性
*/
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;
}

[/code]

common.js 加入:
[code lang=”js”]</pre>
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();
}

[/code]

加入购物车改为:

[code lang=”js”]

Ajax.call(‘flow.php?step=add_to_cart’, ‘goods=’ + obj2str(goods), addToCartResponse, ‘POST’, ‘JSON’);

[/code]