我想尝试使用 HTML 上的小屏幕向文件提供输出。每次单击按钮时,我都希望替换文件中的文本。这是我写的代码:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>This is Web App</title>
</head>
<script>
function createDoc()
{
var doc=document.open("answer.txt","replace");
var txt="<html><body>You clicked Allow</body></html>";
doc.write(txt);
doc.close();
}
function createDoc2()
{
var doc=document.open("answer.txt","replace");
var txt="<html><body>You clicked Deny</body></html>";
doc.write(txt);
doc.close();
}
</script>
<body>
<h1> This is the visitor at your house</h1>
<img src = "./images/chef.gif" width="130" height="101" />
<br />
<button name="Yes" type="button" onclick="createDoc()">Allow! </button>
<button name="No" type="button" onclick="createDoc2()">Deny! </button>
</body>
</html>
我知道这不是正确的方法,但我正在努力学习。请帮助我并指出我的错误,并告诉我如何在可能的情况下纠正它们。我知道可能有很多。我只是想在这一点上自学。非常感谢您的帮助。