以下のコードでは、id='questionaire' のボタンがあります。ユーザーがボタンをクリックすると、イベントをローカルストレージに保存して、ユーザーが次にページを開いたときにボタンが表示されないようにします。
以前に window.onload=function(){} スクリプトを使用してこれを行うことができましたが、ボタンがクリックされた場合、ボタンが一瞬表示されてから消えました。これは見栄えがよくありませんでした。
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Storage?</title>
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<?php
echo "
<form>
<input type='button' class='button' value='Question' id='questionaire'>
</form>
";
echo "<script type='text/javascript'>
document.getElementById('questionaire').onclick = function() {
localStorage.clicked = 'true';
}
</script>";
... <More HTML code> ...
?>
</body>
</html>