ecshop jquery冲突,美化商品属性选择 IE中js无法获得默认属性
发布:smiling 来源: PHP粉丝网 添加日期:2015-12-07 13:00:42 浏览: 评论:0
本文我们来学习一下在ecshop中用jquery美化商品属性,jquery冲突如何解决,在IE中js无法获得默认属性应该如何解决.
ecshop 和 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());
- } //phpfensi.com
- }
- }
- // 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 加入:
- </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();
- }
加入购物车改为:
- Ajax.call('flow.php?step=add_to_cart', 'goods=' + obj2str(goods), addToCartResponse, 'POST', 'JSON');
ECshop在IE下js无法获得默认属性的解决方法.
商品属性美化之后,属性都用 type= hidden 形式,就算给了默认值 checked=true,IE进入第一次加载的时候还是无法获得attr的值。
解决:在goods.dwt 属性加一个默认值 defaultChecked,如:
- <!-- {foreach from=$spec.values item=value key=key} -->
- <span class="fl junma {if $key eq 0}hover{/if}" name="spec_{$spec_key}" value="{$value.id}"> {$value.label}
- </span>
- <input type="hidden" name="spec_{$spec_key}" value="{$value.id}" {if $key eq 0}checked="true" defaultChecked="true"{/if}>
- <!-- {/foreach} -->
common.js里面,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' || formBuy.elements[i].getAttribute('defaultChecked')))
- {
- spec_arr[j] = formBuy.elements[i].value;
- j++ ;
- }
- }
- return spec_arr;
- }
Tags: jquery冲突 ecshop商品属性
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)