var local=this.localStorage; var STORAGE_KEY = 'Local'; var items={"name":"zhang","password":"123456"} var STORAGE_KEY2 = 'Local2'; var items2={"name":"wang","sto":"storage"} local.setItem(STORAGE_KEY, JSON.stringify(items));//把itemJSON话后,添加到LocalStorage,此时在浏览器中可以看到 console.log(local.getItem(STORAGE_KEY));//根据key获取{key:value} console.log(local); local.setItem(STORAGE_KEY2, JSON.stringify(items2)); console.log(local); console.log(local.key(1));
var date=new Date(); var expireDays=10; //将date设置为10天以后的时间 date.setTime(date.getTime()+expireDays*24*3600*1000); document.cookie = 'cookiename=cookievalue;expires=+'+date.toGMTString()+';'; document.cookie = 'cookiez=zhangsad; max-age='+(60*60*24*365)+';path=/;'; function getCookie(c_name){ var i,x,y; var cookieArray = document.cookie.split(";"); console.log(cookieArray); for (i=0;i<cookieArray.length;i++){ x = cookieArray[i].substr(0,cookieArray[i].indexOf("=")); y = cookieArray[i].substr(cookieArray[i].indexOf("=")+1); x = x.replace(/^\s+|\s+$/g,""); console.log(y); if(x == c_name){ return unescape(y); } } } console.log(getCookie('cookiez')); console.log(document.cookie);
var data=new FormData(); data.append("currentPage", 1); data.append("order", "desc"); ajax("","",data);
function ajax(method,url,data){ var xhr ; if (window.XMLHttpRequest) { // Mozilla, Safari, ... xhr = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.addEventListener("progress", updateProgress, false); xhr.addEventListener("load", transferComplete, false); xhr.addEventListener("error", transferFailed, false); xhr.addEventListener("abort", transferCanceled, false); xhr.open(method,url, true); xhr.setRequestHeader("Content-Type","multipart/form-data"); xhr.send(data); }
// progress on transfers from the server to the client (downloads) function updateProgress(evt) { if (evt.lengthComputable) { var percentComplete = evt.loaded / evt.total; console.log("The transfer is updateProgress."); } else { // Unable to compute progress information since the total size is unknown } }
function transferComplete(evt) { console.log(evt); console.log(this.response); console.log(JSON.parse(this.response)); console.log(evt.responseText); console.log("The transfer is complete."); }
function transferFailed(evt) { console.log("An error occurred while transferring the file."); }
function transferCanceled(evt) { console.log("The transfer has been canceled by the user."); }
<video id="video" width="420" style="margin-top:15px;"> <source src="/example/html5/mov_bbb.mp4" type="video/mp4" /> <source src="/example/html5/mov_bbb.ogg" type="video/ogg" /> Your browser does not support HTML5 video. </video>
function phone(){ var options={ enableHighAccuracy:true, maximunAge:1000, timeout:5000 }; if(window.navigator.geolocation){ navigator.geolocation.getCurrentPosition(successCallback,errorCallback,options); }else{ console.log('你的浏览器不支持地理位置!'); } } function successCallback(position){ // 百度地图API功能 var lng = position.coords.longitude; var lat = position.coords.latitude; var point = new BMap.Point(lng, lat); // 创建点坐标//116.331398,39.897445 BMap.Convertor.translate(point,0,translateCallback); console.log('当前地址的经纬度:经度' + lng + ',纬度' + lat); } function translateCallback(point){ console.log(point); var geoc = new BMap.Geocoder();//地址解析类 geoc.getLocation(point, function(rs){ var defCity = { id: '000001', name: '北京', date: new Date()//获取当前时间方法 }; var addComp = rs.addressComponents; console.log(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber); Hander(addComp.city); }); } function errorCallback(error){ switch(error.code){ case error.PERMISSION_DENIED: console.log("you have denied access to your position ."); break; case error.POSITION_UNAVAILABLE: console.log("there was a problem getting yout position ."); break; case error.TIMEOUT: console.log("The application has timed out attempting to get your location ."); break; } }