html - HTML 保存按钮,复选框保持状态
问题描述
假设我正在使用 HTML 来做一些它并不真正适合的事情并让我感到幽默。
我有以下代码示例,但有没有办法将复选框状态保存到下载的 HTML 中?或者有没有人遇到过可以做到这一点的东西?
非常感谢,
<body>
<h1>Show Checkboxes</h1>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label><br><br>
<a href ="#" id="donwload-link" onClick="myFunction()">download html content</a>
<script>
function myFunction() {
var content = document.documentElement.innerHTML;
download(content, "index", "html")
}
function download(content, fileName, fileType) {
var link = document.getElementById("donwload-link");
var file = new Blob([content], {type: fileType});
var donwloadFile = fileName + "." + fileType;
link.href = URL.createObjectURL(file);
link.download = donwloadFile
}
</script>
</body>
</html>
解决方案
推荐阅读
- notepad++ - NppExec SqlPlus 如何检查错误?
- javascript - 如何在Javascript中传递斜杠“\”值
- anaconda - Anaconda 无连接安装包
- c++ - 如何将韦根卡 ID 转换为韦根二进制文件?
- ruby-on-rails - 允许用户延迟完成表单,错误:nil:NilClass 的未定义方法“错误”
- r - 输出“randomForest”并改变 MeanDecreaseAccuracyValues
- google-analytics - Firebase 分析中的“用户”和“活跃用户”有什么区别?
- java - 将查询结果转换为不同的格式
- node.js - 在节点中解析 ldap sid
- cpanel - 面板图像不显示