<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
<script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
</head>
<body>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="A simple HTML5 Template">
<meta name="author" content="dron">
<meta name="viewport" content="width=device-width,
height=device-height, user-scalable=no, initial-scale=1.0,
maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>保存文本文件到本地</title>
<link href="http://ucren.com/static/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="http://ucren.com/static/jquery/2.2.3/jquery.min.js"></script>
<script src="http://ucren.com/static/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
.container-fluid{ margin-top: 20px; }
</style>
</head>
<body>
<script>
void function(a){a.siteToolbar=function b(a){b.setting=a||{}},document.write
('<div class="ucren-toolbar-placeholder" style="height:3000px;"></div><scri'
+'pt src="//ucren.com/ucren-toolbar/scripts/main.js"></script>')}(this);
siteToolbar();
</script>
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label>文件内容</label>
<textarea class="form-control" rows="4" id="content">测试文本,你可以随便修改,完事后点保存。</textarea>
</div>
<div class="form-group">
<label>文件名</label>
<input type="text" class="form-control" value="test.txt" id="file-name">
</div>
<a id="save-btn" class="btn btn-default" download="test.txt" role="button">保存</a>
</div>
</div>
</div>
<script>
void function(){
var content, fileName, saveBtn;
content = document.querySelector( '#content' );
fileName = document.querySelector( '#file-name' );
saveBtn = document.querySelector( '#save-btn' );
content.addEventListener( 'change', function self(){
saveBtn.setAttribute( 'href', 'data:text/paint; utf-8,' + content.value );
return self;
}() );
fileName.addEventListener( 'change', function self(){
saveBtn.setAttribute( 'download', fileName.value );
return self;
}() );
}();
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-4190821-1', 'ucren.com');
ga('send', 'pageview');
</script>
</body>
</html>
</body>
</html>