# JS写文件
~~~
<script>
function saveShareContent(content, file) {
let link = document.createElement('a')
let blob = new Blob([content])
link.download = file
link.href = URL.createObjectURL(blob)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
for (let i = 0; i < 3; i++) {
saveShareContent(i, 'log' + i + '.txt');
}
</script>
~~~
# indexedDB数据库
~~~
<script>
const request = indexedDB.open('myDatabase', 3);
request.addEventListener('success', e => {
const db = e.target.result;
const tx = db.transaction('User','readwrite');
const store = tx.objectStore('User');
const reqAdd = store.add({'userId': 1, 'name': '123'});
reqAdd.addEventListener('success', e => {
console.log('保存成功')
})
});
</script>
~~~