//json兼容ie6、7 if (!this.json) { this.json = {}; } (function () { function f(n) { // format integers to have at least two digits. return n < 10 ? '0' + n : n; } if (typeof date.prototype.tojson !== 'function') { date.prototype.tojson = function (key) { return isfinite(this.valueof()) ? this.getutcfullyear() + '-' + f(this.getutcmonth() + 1) + '-' + f(this.getutcdate()) + 't' + f(this.getutchours()) + ':' + f(this.getutcminutes()) + ':' + f(this.getutcseconds()) + 'z' : null; }; string.prototype.tojson = number.prototype.tojson = boolean.prototype.tojson = function (key) { return this.valueof(); }; } var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = { // table of character substitutions '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\' }, rep; function quote(string) { escapable.lastindex = 0; return escapable.test(string) ? '"' + string.replace(escapable, function (a) { var c = meta[a]; return typeof c === 'string' ? c : '\\u' + ('0000' + a.charcodeat(0).tostring(16)).slice(-4); }) + '"' : '"' + string + '"'; } function str(key, holder) { var i, // the loop counter. k, // the member key. v, // the member value. length, mind = gap, partial, value = holder[key]; if (value && typeof value === 'object' && typeof value.tojson === 'function') { value = value.tojson(key); } if (typeof rep === 'function') { value = rep.call(holder, key, value); } switch (typeof value) { case 'string': return quote(value); case 'number': return isfinite(value) ? string(value) : 'null'; case 'boolean': case 'null': return string(value); case 'object': if (!value) { return 'null'; } gap += indent; partial = []; if (object.prototype.tostring.apply(value) === '[object array]') { length = value.length; for (i = 0; i < length; i += 1) { partial[i] = str(i, value) || 'null'; } v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']'; gap = mind; return v; } if (rep && typeof rep === 'object') { length = rep.length; for (i = 0; i < length; i += 1) { k = rep[i]; if (typeof k === 'string') { v = str(k, value); if (v) { partial.push(quote(k) + (gap ? ': ' : ':') + v); } } } } else { for (k in value) { if (object.hasownproperty.call(value, k)) { v = str(k, value); if (v) { partial.push(quote(k) + (gap ? ': ' : ':') + v); } } } } v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}'; gap = mind; return v; } } if (typeof json.stringify !== 'function') { json.stringify = function (value, replacer, space) { var i; gap = ''; indent = ''; if (typeof space === 'number') { for (i = 0; i < space; i += 1) { indent += ' '; } } else if (typeof space === 'string') { indent = space; } rep = replacer; if (replacer && typeof replacer !== 'function' && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) { throw new error('json.stringify'); } return str('', {'': value}); }; } if (typeof json.parse !== 'function') { json.parse = function (text, reviver) { var j; function walk(holder, key) { var k, v, value = holder[key]; if (value && typeof value === 'object') { for (k in value) { if (object.hasownproperty.call(value, k)) { v = walk(value, k); if (v !== undefined) { value[k] = v; } else { delete value[k]; } } } } return reviver.call(holder, key, value); } text = string(text); cx.lastindex = 0; if (cx.test(text)) { text = text.replace(cx, function (a) { return '\\u' + ('0000' + a.charcodeat(0).tostring(16)).slice(-4); }); } if (/^[\],:{}\s]*$/. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fa-f]{4})/g, '@'). replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[ee][+\-]?\d+)?/g, ']'). replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { j = eval('(' + text + ')'); return typeof reviver === 'function' ? walk({'': j}, '') : j; } // if the text is not json parseable, then a syntaxerror is thrown. throw new syntaxerror('json.parse'); }; } }()); //自定义方法 var jq = jquery.noconflict(); jq.cookie = function(name, value, options) { if (typeof value != 'undefined') { // name and value given, set cookie options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toutcstring)) { var date; if (typeof options.expires == 'number') { date = new date(); date.settime(date.gettime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = '; expires=' + date.toutcstring(); // use expires attribute, max-age is not supported by ie } var path = options.path ? '; path=' + options.path : ''; var domain = options.domain ? '; domain=' + options.domain : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeuricomponent(value), expires, path, domain, secure].join(''); } else { // only name given, get cookie var cookievalue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jquery.trim(cookies[i]); if (cookie.substring(0, name.length + 1) == (name + '=')) { cookievalue = decodeuricomponent(cookie.substring(name.length + 1)); break; } } } return cookievalue; } }; function getcookie(name) { var cookie_start = document.cookie.indexof(name); var cookie_end = document.cookie.indexof(";", cookie_start); return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length))); } function setcookie(cookiename, cookievalue, seconds, path, domain, secure) { var expires = new date(); expires.settime(expires.gettime() + seconds); document.cookie = escape(cookiename) + '=' + escape(cookievalue) + (expires ? '; expires=' + expires.togmtstring() : '') + (path ? '; path=' + path : '/') + (domain ? '; domain=' + domain : '') + (secure ? '; secure' : ''); } function savecookie(reurl,title,model,imageurl){ if(reurl==""){ return; } if(title==""){ return; } if(model==""){ return; } if(imageurl==""){ return; } var arr2 = new array(); var newpro = new array(reurl,title,model,imageurl); var proshuzu = jq.cookie('producthistory'); if(proshuzu!=null && proshuzu!=''){ var ss = proshuzu.split(","); for(var l=0; l3){//大于三个,得到最新的三个放在当前的数组中 for(var k=0; k<3; k++){ var num11 = new array(ss[4*k],ss[4*k+1],ss[4*k+2],ss[4*k+3]); arr2.push(num11); pro = pro-1; } }else{//三个或三个一下直接再把它们重新添加到数组中 for(var j=pro; j>0; j--){ var num11 = new array(ss[j*4-4],ss[j*4-3],ss[j*4-2],ss[j*4-1]); arr2.unshift(num11); } } } arr2.unshift(newpro);//把当前浏览的产品信息放在数组的最前端 jq.cookie('producthistory', arr2,{expires: 7,path:'/cn/',domain:'haier.com'}); } //判断当前是否存在同域cookie function istrsidssdssotoken(){ var trsidssdssotoken = "trsidssdssotoken";//同域cookie var sdssotoken = jq.cookie(trsidssdssotoken); if(sdssotoken!=null){ return true; }else{ return false; } } var $ = jquery.noconflict(); //常见问题分页 (function($){ //分页效果 var xmldata = null; var dataurl = null; var dataurltpl = null; var pagecounttpl = 0; var pageidtpl = null; var pagedatatpl = null; var pageincludetpl = 0; //分页数量 var pageindextpl = 0; var record_count = 0; var makeurl = function() {dataurl = dataurltpl.replace("[n]", (pageindextpl-1) > 0 ? '_' + (pageindextpl-1) : ''); } var showdata = function (){ $(pagedatatpl).html("") for(var i = 0 ;i < xmldata.length ;i++){ $(pagedatatpl).append(insertitem(xmldata[i])) } new pager().render(); } var getpage = function() { makeurl(); $.ajax({ type: "get", datatype: "xml", url: dataurl, cache: false, async: false, success: function (xml){ xmldata = $(xml).find("item"); pagecounttpl = $(xml).find("pagecount").text(); record_count = $(xml).find("recordcount").text(); showdata(); }, error: function (xml) { xmldata = null; } }); } var pager = function(){ var $this = this; this._start = 1; this._end = 1; /** * 在显示之前计算各种页码变量的值 */ this._calculate = function(){ if(pagecounttpl<5){ pageincludetpl=pagecounttpl; } pageindextpl = parseint(pageindextpl); if(pageindextpl>pagecounttpl){ pageindextpl = pagecounttpl; } if(pageindextpl<1){ pageindextpl = 1; } $this._start = math.max(1, pageindextpl - parseint(pageincludetpl/2));// $this._end = math.min(pagecounttpl, $this._start + pageincludetpl - 1);//最后一个页码按钮的页码数 $this._start = math.max(1, $this._end - pageincludetpl + 1);//第一个页码按钮的页码数 } this.render = function(){ $this._calculate(); var htmlstr = ""; var currpage = pageindextpl; htmlstr += ''; if(1!=currpage){ htmlstr+= '上一页 '; } if(1!=currpage){ htmlstr+= '1'; } var temp1=pageincludetpl-2; if(pagecounttpl<=pageincludetpl){ temp1=pageincludetpl; } if(currpage > temp1 ){ if(currpage > 4 && pagecounttpl > 5){ htmlstr+= '...'; } } for(var i=$this._start;i<=$this._end;i++){ if(i==currpage){ htmlstr+= ''+i+' '; }else{ if(i!=1 && i!=pagecounttpl){ htmlstr+= ''+i+' '; } } } var temp=pageincludetpl-2; if(pagecounttpl<=pageincludetpl){ temp=pageincludetpl; } if (currpage < pagecounttpl) { if(currpage != pagecounttpl-2&&currpage != pagecounttpl-1){ if(pagecounttpl > 5){ htmlstr+= '...'; } } } if (currpage != pagecounttpl) { htmlstr+= ''+pagecounttpl+' '; } if(pagecounttpl!=currpage){ htmlstr += '下一页 '; } htmlstr += ' '; htmlstr += '共' + record_count + '个结果 ' + currpage + '/' + pagecounttpl + ''; $(pageidtpl).html(htmlstr); var a_list = $(pageidtpl).find("a"); for(var i=0;i 0 ? '_' + (pageindextpl-1) : ''); } var showdata = function (){ $(pagedatatpl).html("") for(var i = 0 ;i < xmldata.length-1 ;i++){ $(pagedatatpl).append(insertitem(xmldata[i])); } $(pagedatatpl).append(insertitemlast(xmldata[i])); new pager().render(); } var getpage = function() { makeurl(); $.ajax({ type: "get", datatype: "xml", url: dataurl, cache: false, async: false, success: function (xml){ xmldata = $(xml).find("item"); pagecounttpl = $(xml).find("pagecount").text(); record_count = $(xml).find("recordcount").text(); showdata(); }, error: function (xml) { xmldata = null; } }); } var pager = function(){ var $this = this; this._start = 1; this._end = 1; /** * 在显示之前计算各种页码变量的值 */ this._calculate = function(){ if(pagecounttpl<5){ pageincludetpl=pagecounttpl; } pageindextpl = parseint(pageindextpl); if(pageindextpl>pagecounttpl){ pageindextpl = pagecounttpl; } if(pageindextpl<1){ pageindextpl = 1; } $this._start = math.max(1, pageindextpl - parseint(pageincludetpl/2));// $this._end = math.min(pagecounttpl, $this._start + pageincludetpl - 1);//最后一个页码按钮的页码数 $this._start = math.max(1, $this._end - pageincludetpl + 1);//第一个页码按钮的页码数 } this.render = function(){ $this._calculate(); var htmlstr = ""; var currpage = pageindextpl; htmlstr += ''; if(1!=currpage){ htmlstr+= '首页 '; htmlstr+= '上一页 '; } if(1!=currpage){ htmlstr+= '1'; } var temp1=pageincludetpl-2; if(pagecounttpl<=pageincludetpl){ temp1=pageincludetpl; } if(currpage > temp1 ){ if(currpage > 4 && pagecounttpl > 5){ htmlstr+= '...'; } } for(var i=$this._start;i<=$this._end;i++){ if(i==currpage){ htmlstr+= ''+i+' '; }else{ if(i!=1 && i!=pagecounttpl){ htmlstr+= ''+i+' '; } } } var temp=pageincludetpl-2; if(pagecounttpl<=pageincludetpl){ temp=pageincludetpl; } if (currpage < pagecounttpl) { if(currpage != pagecounttpl-2&&currpage != pagecounttpl-1){ if(pagecounttpl > 5){ htmlstr+= '...'; } } } if (currpage != pagecounttpl) { htmlstr+= ''+pagecounttpl+' '; } if(pagecounttpl!=currpage){ htmlstr += '下一页 '; htmlstr+= '尾页 '; } htmlstr += ' '; htmlstr += '共' + record_count + '个结果 ' + currpage + '/' + pagecounttpl + ''; $(pageidtpl).html(htmlstr); var a_list = $(pageidtpl).find("a"); for(var i=0;i¥"+price+""); $("#esalenum").html("已售出:"+salenum+" 台"); $(".eh-purchase-param-destination p").html(sevpromiseinfo) ; if(stock==0 && isbookable==0){ $("#nr_add_car").hide();//加入购物车按钮隐藏 $("#nr_add_car_disabled").show();//加入购物车按钮隐藏 } }else{ //if(code==01){//1.商城系统错误 $("#nr_add_car").hide(); $("#nr_add_car_disabled").show(); $("#nr_add_car_disabled").addclass("nr_add_car_disabled"); $("#eprice").html(message); $("#esalenum").html(""); //} /*else if(code==02){//2.未找到匹配商品 }else if(code==03){//3.未找到匹配区域 }else if(code==04){//4.商品实行了区域限购 }else if(code==05){//5.商品实行了特定用户组购买code }*/ } } }); } , error: function(xhr){ //jsonp 方式此方法不被触发 //请求出错处理 alert("请求出错(请检查相关度网络状况.)"); } }); //获取配送省市区,绘制联动js $.ajax({ url: "http://www.ehaier.com/region.php?a=outregionjsonnourl", datatype: "jsonp", async:false, jsonp:'callback', success: function( data ) { var provincehtml = "" ; for(var i=0;i"+name+"" ; } $(".param-province").append( provincehtml ) ; } }); $(".eh-purchase-param").show();//售出及配送显示 //$(".nr_add_car").show();//加入购物车按钮显示 }else{ $("#nr_add_car").hide();//加入购物车按钮隐藏 $("#nr_add_car_disabled").show();//加入购物车按钮隐藏 $("#nr_add_car_disabled").addclass("nr_add_car_disabled"); } }else{ $("#nr_add_car").hide();//加入购物车按钮隐藏 $("#nr_add_car_disabled").show();//加入购物车按钮隐藏 $("#nr_add_car_disabled").addclass("nr_add_car_disabled"); } } }); //省更改时 $(".param-province").change(function(){ var provinceid = $(".param-province option:selected").attr("value"); getcity(provinceid); }); //城市更改时 $(".param-city").change(function(){ var provinceid = $(".param-province option:selected").attr("value"); var cityid = $(".param-city option:selected").attr("value"); if(cityid!=""){ getdistrict(provinceid,cityid); } }); //地区更改时 $(".param-district").change(function(){ //var provinceid = $(".param-province option:selected").attr("value"); //var cityid = $(".param-city option:selected").attr("value"); var districtid = $(".param-district option:selected").attr("value"); if(districtid!=""){ chooseregion(districtid); } }); //继续购买 $(".goonbuy").click(function(){ $("#fancybox-close").click(); }); $("#nr_add_car").click(function(){ //调用商城加入购物车接口 jquery.ajax({ url:"http://www.ehaier.com/cart/addtocartjsonp?sku="+pcode, datatype:"jsonp", jsonp:'callback', timeout: 3000, async: false, success:function(data){ var issuccess = data.success ; if(issuccess==true){ var totalnum = data.data.totalnum ; var totalprice = data.data.totalprice ; $("#salenum").html(totalnum); $("#totalprice").html(totalprice); }else{ //alert("加入购物车失败~");//加入购物车失败 } }, error:function(){ } }); $("#nr_add_car_click").click(); }); $("#nr_add_car_disabled").click(function(){ $(".eh-purchase-param-select-area").click(); }); $(".eh-purchase-param-select-area").mouseout(function(){ $('.eh-purchase-param-places').show(); }); $(".eh-purchase-param").mouseleave(function(){ $('.eh-purchase-param-places').hide(); }); }); function getcity(provinceid){ $(".param-city").html(''); $(".param-district").html(''); jquery.ajax({ url:"http://www.ehaier.com/region.php?a=outregionjsonnourl", datatype:"jsonp", jsonp:'callback', timeout: 3000, async: false, success:function(data){ var citys = returnchilds(provinceid,data) ; var cityhtml = "" ; for(var i=0;i"+name+"" ; } $(".param-city").append( cityhtml ) ; }, error:function(){ } }); } function getdistrict(provinceid,cityid){ $(".param-district").html(''); jquery.ajax({ url:"http://www.ehaier.com/region.php?a=outregionjsonnourl", datatype:"jsonp", jsonp:'callback', timeout: 3000, async: false, success:function(data){ var districthtml = "" ; var citys = returnchilds(provinceid,data) ; var districts = returnchilds(cityid,citys) ; for(var i=0;i"+name+"" ; } $(".param-district").append( districthtml ) ; }, error:function(){ } }); } function returnchilds(id,data){ var objdata ; for(var i=0;i¥"+price+""); $("#esalenum").html("已售出:"+salenum+" 台"); $(".eh-purchase-param-destination p").html(sevpromiseinfo) ; if(stock==0&&isbookable==0){ $("#nr_add_car").hide();//加入购物车按钮隐藏 $("#nr_add_car_disabled").show();//加入购物车按钮隐藏 $("#nr_add_car_disabled").addclass("nr_add_car_disabled"); //$("#nr_add_car").unbind("click",addcar); //$("#nr_add_car").bind("click",areaclick); }else{ $("#nr_add_car").show();//加入购物车按钮隐藏 $("#nr_add_car_disabled").hide();//加入购物车按钮隐藏 //$(".nr_add_car").show();//加入购物车按钮显示 //$("#nr_add_car").removeclass("nr_add_car_disabled"); //$("#nr_add_car").unbind("click",areaclick); //$("#nr_add_car").on("click",bindclick); //$("#nr_add_car").bind("click",areaclick ); } }else{ $("#nr_add_car").hide();//加入购物车按钮隐藏 $("#nr_add_car_disabled").show();//加入购物车按钮隐藏 //$(".nr_add_car").hide();//加入购物车按钮隐藏 //$(".nr_add_car").attr("css","nr_add_car_disabled");//加入购物车按钮隐藏 //$("#nr_add_car").removeclass("nr_add_car"); $("#nr_add_car_disabled").addclass("nr_add_car_disabled"); //$("#nr_add_car").unbind("click",addcar); //$("#nr_add_car").bind("click",areaclick); } } }); //}else{ // $(".eh-purchase-param").hide();//售出及配送隐藏 // $(".nr_add_car").hide();//加入购物车按钮隐藏 //} } , error: function(xhr){ //jsonp 方式此方法不被触发 //请求出错处理 alert("请求出错(请检查相关度网络状况.)"); } }); } function bindclick() { //调用商城加入购物车接口 jquery.ajax({ url:"http://www.ehaier.com/cart/addtocartjsonp?sku="+pcode, datatype:"jsonp", jsonp:'callback', timeout: 3000, async: false, success:function(data){ var issuccess = data.success ; if(issuccess==true){ var totalnum = data.data.totalnum ; var totalprice = data.data.totalprice ; $("#salenum").html(totalnum); $("#totalprice").html(totalprice); }else{ //alert("加入购物车失败~");//加入购物车失败 } }, error:function(){ } }); $("#nr_add_car_click").click(); }