我一直试图创建一个表单,当用户单击按钮时,它会从2个文本输入中下载输入并将其保存到文件中。我的代码是:
<html>
<head>
<script>
var username = document.forms['login'].username.value
var password = document.forms['login'].password.value
function createResult(){
result =
`
username=${username}
password=${password}
`;
download(document.forms['login'].name.value+".txt",result)
}
</script>
<body>
<form id="login">
<input type="text" id="username">
<input type="text" id="password">
</form>
<button onclick="createResult()" />
</body>
</html>