js点击按钮保存数据到本地

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>05_淡入淡出动画效果</title>
</head>
<body>
<input id="add" type="button" value="添加" />  

<script src="http://code.jquery.com/jquery-1.4.1.min.js"></script>  
  <script>  
   
    $("#add").bind("click", function () {  
            var content = "123123"
                var fileName = 'test.pem'
                var aLink = document.createElement('a');
                var blob = new Blob([content]);
                var evt = document.createEvent("HTMLEvents");
                evt.initEvent("click", false, false);
                aLink.download = fileName;
                aLink.href = URL.createObjectURL(blob);
                aLink.dispatchEvent(evt);
                aLink.click();
                })
   
     
  </script>  
</body>
</html>

 

posted @ 2018-06-28 13:57  秀&莹&锐  阅读(6304)  评论(0编辑  收藏  举报