【发布时间】:2019-10-26 08:39:04
【问题描述】:
我有一个带有文本和复选框输入的 HTML 表单,我想在提交表单时将此表单数据下载到文本文件中。
我将found a solution to download data from a textbox 写入一个文本文件,但我不知道如何修改它以获取我需要的其他文本和复选框输入。
这是我当前的代码:
<html>
<head>
<script language="Javascript">
function download(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' +
encodeURIComponent(Notes));
pom.setAttribute('download', filename);
pom.style.display = 'none';
document.body.appendChild(pom);
pom.click();
document.body.removeChild(pom);
}
function addTextTXT() {
document.addtext.name.value = document.addtext.name.value + ".txt"
}
</script>
</head>
<body>
<form name="addtext" onsubmit="download(this['name'].value, this[’Notes’].value)">
Notes:<input type="text" name=“Note/Users/karlahaiat/Desktop/Copia de checklist.htmls”><br>
Initials:<input type="text" name=“Initials”><br>
<input type="checkbox" name=“check_list[]” value=“Check General Health”>
<b>Check General Health.</b><br>
<input type="checkbox" name=“check_list[]” value=“Check Fluid”>
<b>Check Fluid.</b><br>
<input type="text" name="name" value="" placeholder="File Name">
<input type="submit" onClick="addTexttxt();" value="Save As TXT">
</form>
</body>
</html>
上面的表格显示了我想要在我的表格中输入的字段,但是文本文件不会下载。任何理解语法的帮助都会很棒!
【问题讨论】:
-
您希望值如何出现在文本字段中?您可能也想检查您的 HTML;它使用“印刷引号”(弯引号),这在 HTML 中无效。
标签: javascript html forms checkbox