HTML5 ? ???
HTML5 ? ???
HTML5 ? ???? ???? ? ?? ?? ?? ?????.
HTML5 ? ????? ??????
HTML5? ???? ???? ?? ???? ??? ??? ? ????.
???? ?? ????? ??? ??????. ??? ? ????? ?? ???? ??? ???. ???? ??? ???? ??? ???? ???? ???? ??? ?? ???? ?????. ?? ???? ??? ??? ?? ?? ?? ?? ???? ??? ?? ????.
???? ?/? ??? ????, ????? ???? ?? ??????? ???? ??? ? ????.
localStorage ? sessionStorage
?????? ???? ???? ?? ? ?? ??? ??? ????.
localStorage - ?? ?? ?? ??? ??
sessionStorage - ???? ?? ??
? ???? ???? ?? ????? localStorage ? sessionStorage? ????? ???? ???:
if(typeof(Storage)!=="undefined") { // Yes! localStorage and sessionStorage support! // Some code..... } else { // Sorry! No web storage support.. }
localStorage ??
???? ????? ?? ??? ????. localStorage ??? ??. ???? ?? ?, ?? ? ?? ?? ???? ?? ??? ? ????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <div id="result"></div> <script> if(typeof(Storage)!=="undefined") { localStorage.lastname="Smith"; document.getElementById("result").innerHTML="Last name: " + localStorage.lastname; } else { document.getElementById("result").innerHTML="Sorry, your browser does not support web storage..."; } </script> </body> </html>
?? ?:
key="lastname" ? value="Smith"? ???? localStorage ?/? ? ??
? ? " lastname" ?? ?? id="result"
? ??? ???? ?????. ?: ?/? ?? ????? ???? ???? ??? ?? ? ??? ??? ? ????.
?? ???? ???? ??? ??? ??? ?????. ??? ??? ?? ?? ???? ?????.
<!DOCTYPE html> <html> <head> <script> function clickCounter() { if(typeof(Storage)!=="undefined") { if (localStorage.clickcount) { localStorage.clickcount=Number(localStorage.clickcount)+1; } else { localStorage.clickcount=1; } document.getElementById("result").innerHTML="You have clicked the button " + localStorage.clickcount + " time(s)."; } else { document.getElementById("result").innerHTML="Sorry, your browser does not support web storage..."; } } </script> </head> <body> <p><button onclick="clickCounter()" type="button">點我</button></p> <div id="result"></div> <p>單擊該按鈕查看計數(shù)器增加.</p> <p>關閉瀏覽器選項卡(或窗口),再試一次,計數(shù)器將繼續(xù)計數(shù)(不是重置)。</p> </body> </html>
sessionStorage ??
sessionStorage ???? ?? ??? ?? ???? ?????. ???? ???? ?? ??? ???? ?????.
sessionStorage? ??? ????? ??: :
<!DOCTYPE html> <html> <head> <script> function clickCounter() { if(typeof(Storage)!=="undefined") { if (sessionStorage.clickcount) { sessionStorage.clickcount=Number(sessionStorage.clickcount)+1; } else { sessionStorage.clickcount=1; } document.getElementById("result").innerHTML="You have clicked the button " + sessionStorage.clickcount + " time(s) in this session."; } else { document.getElementById("result").innerHTML="Sorry, your browser does not support web storage..."; } } </script> </head> <body> <p><button onclick="clickCounter()" type="button">Click me!</button></p> <div id="result"></div> <p>單擊該按鈕查看計數(shù)器增加.</p> <p>關閉瀏覽器選項卡(或窗口),再試一次,計數(shù)器將繼續(xù)計數(shù)(不是重置)。</p> </body> </html>