<!DOCTYPE html>
<html>
<head>
<script>
function clickCounter()
{
if(typeof(Storage)=="undefined") {
document.getElementById("result").innerHTML="Sorry, your browser does not support web storage...";
}
localStorage.clickcount=Number(localStorage.clickcount)+1 || 1;
document.getElementById("result").innerHTML="You have clicked the button " + localStorage.clickcount + " time(s).";
}
function toggleInterval(toggle)
{
if(toggle=="on") {
this.int = setInterval(clickCounter, 1);
}else{
clearInterval(int);
}
}
function clickToggle()
{
var button = document.getElementById("button1");
var toggleStatus = button.attributes.toggle.value;
if(toggleStatus == "on"){
button.setAttribute("toggle","off")
toggleInterval("off");
} else {
button.setAttribute("toggle","on")
toggleInterval("on");
}
}
</script>
</head>
<body>
<p><button id="button1" onclick="clickToggle()" type="button" toggle="off">Click me!</button></p>
<div id="result"></div>
<p>Click the button to see the counter increase.</p>
<p>Close the browser tab (or window), and try again, and the counter will continue to count (is not reset).</p>
</body>
</html>
댓글
댓글 쓰기