tailieunhanh - giới thiều ebook HTML5 và CSS3 in the real world phần 10
Tham khảo tài liệu 'giới thiều ebook html5 và css3 in the real world phần 10', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Geolocation Offline Web Apps and Web Storage 257 localStorage email email localStorage remember true Now that we have a function to save the visitor s name and email address let s call it if they check the Remember me on this computer checkbox. We ll do this by watching for the change event on the checkbox this event will fire whenever the checkbox s state changes whether due to a click on it a click on its label or a keyboard press js excerpt document .ready function rememberme .change saveData Next let s make sure the checkbox is actually checked since the change event will fire when the checkbox is unchecked as well js excerpt function saveData if rememberme .attr checked var email address .val var name register-name .val localStorage name name localStorage email email localStorage remember true This new line of code calls the jQuery method attr checked which will return true if the checkbox is checked and false if not. Finally let s ensure that Web Storage is present in our visitor s browser 258 HTML5 CSS3 for the Real World js excerpt function saveData if if rememberme .attr checked var email address .val var name register-name .val localStorage name name localStorage email email localStorage remember true else no support for Web Storage Now we re saving our visitor s name and email whenever the checkbox is checked so long as local storage is supported. The problem is we have yet to actually do anything with that data Let s add another function to check and see if the name and email have been saved and if so fill in the appropriate input elements with that information. Let s also precheck the Remember me checkbox if we ve set the key remember to true in local storage js excerpt function loadStoredDetails var name localStorage name var email localStorage email var remember localStorage remember if name name .val name if email email .val name if remember true Geolocation Offline Web .
đang nạp các trang xem trước