2017年4月21日金曜日

開発環境

Head First HTML5 Programming (Elisabeth Robson (著)、Eric Freeman (著)、O'Reilly Media)の Chapter 9.(Storing Things Locally: Web Storage)、EXERCISE(No. 2680) を取り組んでみる。

EXERCISE(No. 2680)

コード(Emacs)

HTML5

<pre id="output0"></pre>
<button id="run0">run</button>
<button id="clear0">clear</button>

<script src="sample1.js"></script>

JavaScript

let btn0 = document.querySelector('#run0'),
    btn1 = document.querySelector('#clear0'),
    pre0 = document.querySelector('#output0'),
    p = (x) => pre0.textContent += x + '\n';

let output = () => {
    localStorage.setItem('sticky_0', 'Pick up dry cleaning');
    localStorage.setItem('sticky_1', 'Cancel cable tv, who needs it now?');

    let sticky = localStorage.getItem('sticky_0');
    p(sticky);
};

btn0.onclick = output;
btn1.onclick = () => pre0.textContent = '';

output();











 
						

0 コメント:

コメントを投稿

Comments on Google+: