HTML5 ? ???
HTML5 ? ????? ??????
HTML5? ???? ??? ?? ???? ??? ???? ?? ???? ? ?? ?? ?? ?????.
???? ?? ????? ??? ??????. ??? ? ????? ?? ???? ??? ???. ???? ??? ???? ??? ???? ???? ???? ??? ?? ???? ?????. ?? ???? ??? ??? ?? ?? ?? ?? ???? ??? ?? ????.
???? ?/? ??? ????, ????? ???? ?? ??????? ???? ??? ? ????.
???? ??
Internet Explorer 8+, Firefox, Opera, Chrome ? Safari? ? ???? ?????.
??: Internet Explorer 7 ?? IE ??? ? ???? ???? ????.
localStorage ? sessionStorage
????? ?? ???? ???? ?? ? ?? ??? ??? ????:
localStorage - ?? ?? ?? ??? ??
sessionStorage - ??? ?? ??? ??
? ???? ???? ?? ????? ????? ???? ???. localStorage ? sessionStorage:
if(typeof(Storage)!=="undefine")
{
// sessionStorage localStorage ??!
// ?? ??....
}
else
{
// ?????. ? ???? ???? ????
}
localStorage ??
localStorage ??? ?? ???? ????? ?? ??? ????. ???? ?? ?, ?? ? ?? ?? ???? ?? ??? ? ????.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <div id="result"></div> <script> if(typeof(Storage)!=="undefined") { localStorage.lastname="劉奇"; document.getElementById("result").innerHTML="姓名: " + localStorage.lastname; } else { document.getElementById("result").innerHTML="對(duì)不起,您的瀏覽器不支持web存儲(chǔ)……"; } </script> </body> </html>
????? ???? ??? ???
???? ??:
key="lastname" ? value=? ???? localStorage ?/?? ?????. "Smith"
? ?? ?? "lastname"? ?? ???? id="result"? ??? ???? ?????.
?: ?/? ?? ??? ????. ????? ??? ?????? ??? ?? ??? ??? ? ????.
?? ?? ???? ??? ??? ??? ?????. ??? ??? ?? ?? ???? ?????.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>php中文網(wǎng)(php.cn)</title> <script> function clickCounter() { if(typeof(Storage)!=="undefined") { if (localStorage.clickcount) { localStorage.clickcount=Number(localStorage.clickcount)+1; } else { localStorage.clickcount=1; } document.getElementById("result").innerHTML="點(diǎn)擊按鈕" + localStorage.clickcount + " time(s)."; } else { document.getElementById("result").innerHTML="對(duì)不起,您的瀏覽器不支持web存儲(chǔ)……"; } } </script> </head> <body> <p><button onclick="clickCounter()" type="button">點(diǎn)擊</button></p> <div id="result"></div> <p>單擊該按鈕查看計(jì)數(shù)器增加。</p> <p>關(guān)閉瀏覽器選項(xiàng)卡(或窗口),再試一次,計(jì)數(shù)器將繼續(xù)計(jì)數(shù)(不是重置)。</p> </body> </html>
????? ???? ??? ???
sessionStorage ??
sessionStorage ??? ??? ?? ???? ?????. ???? ???? ?? ??? ???? ?????.
?? ??? ?? ? ??? ??: :
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>php中文網(wǎng)(php.cn)</title> <script> function clickCounter() { if(typeof(Storage)!=="undefined") { if (sessionStorage.clickcount) { sessionStorage.clickcount=Number(sessionStorage.clickcount)+1; } else { sessionStorage.clickcount=1; } document.getElementById("result").innerHTML="點(diǎn)擊按鈕 " + sessionStorage.clickcount + " time(s) "; } else { document.getElementById("result").innerHTML="對(duì)不起,您的瀏覽器不支持web存儲(chǔ)……"; } } </script> </head> <body> <p><button onclick="clickCounter()" type="button">點(diǎn)擊</button></p> <div id="result"></div> <p>單擊該按鈕查看計(jì)數(shù)器增加。</p> <p>關(guān)閉瀏覽器選項(xiàng)卡(或窗口),再試一次,計(jì)數(shù)器復(fù)位</p> </body> </html>
????? ???? ??? ???