//写cookies function setCookie(name,value) { var Days = 1; var Hours = 1; var exp = new Date(); exp.setTime(exp.getTime() + Days*Hours*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); } //读取cookies function getCookie(name) { var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); if(arr=document.cookie.match(reg)) return unescape(arr[2]); else return null; } function getLocation() { var map, geolocation; map = new AMap.Map('allmap'); map.plugin('AMap.Geolocation', function() { geolocation = new AMap.Geolocation({ enableHighAccuracy: true //是否使用高精度定位,默认:true }); geolocation.getCurrentPosition(); AMap.event.addListener(geolocation, 'complete', getPositionInfo);//返回定位信息 AMap.event.addListener(geolocation, 'error', function(){ getPositionInfo(); }); }); } function getPositionInfo(data) { if(typeof data != 'undefined') { var point = data.position; var lnglatXY = [point.lng, point.lat]; //已知点坐标 var map = new AMap.Map('allmap'); map.plugin('AMap.Geocoder', function() { var geocoder = new AMap.Geocoder(); geocoder.getAddress(lnglatXY, function(status, result) { if (status === 'complete' && result.info === 'OK') { var obj = result.regeocode.addressComponent; var position = result.regeocode.formattedAddress; position = position.replace(obj.province, ''); position = position.replace(obj.district, ''); position = position.replace(obj.city, ''); //$('#position').html(position); var dwCity = obj.city; dwCity = dwCity.replace("市",""); setCookie('dwcity',dwCity) if(dwCity!='威海') { var r=confirm("当前定位城市是"+dwCity +", 是否切换?") if (r==true) { window.location="/wap/index/dw.html"+'?city='+ dwCity; } } } }); }); } } if(getCookie("dwcity")==null ) { } $("#searchBtn").click(function(){ console.log("sss"+$("#searchContent").attr("value")); if($("#searchContent").attr("value").length==0) { alert("请输入关键词"); } else { window.location= "https://www.zhaotie.com/wap/index/searchsimple"+'?keyword='+ $("#searchContent").attr("value")+"&cityid="+cityid; } return false; });