html+js+localStorage实现简易记事本

简介

可保存,下次打开内容不会丢失

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>简易记事本</title>
</head>
<body>
        <p>实现简易记事本</p>
        <textarea name="tex" id="mytxt" cols="30" rows="10"></textarea>
        <button onclick="save()">保存</button>
        <script>
            window.onload=function(){
                var y=localStorage.getItem("txt");
                document.getElementById('mytxt').innerHTML = y;
              
            }
           function save(){
               var x = document.getElementById('mytxt').value;
                localStorage.setItem("txt",x);
               
           }
        </script>
</body>
</html>

你可能感兴趣的:(js)