我刚开始学习,并与同学们一起创建了一个在线工作簿,但无法将答案下载为文本文件。尽管文件已经下载,但当我们打开文件时,会出现"undefined"。这段代码可以在Outlook中使用,但是学生们没有Outlook,他们使用基于Web的Office 365电子邮件。我不允许使用我们的SMTP服务器发送电子邮件。邮件内容如下:姓名=学生姓名,在此处显示答案1.1=在此处显示答案1.2=1.3=1.4=1.5=1.6=以此类推。下面是我的代码示例:
<form onsubmit="download(this['name'].value, ['text'].value, ['id'].value)">
<h4>Students Name<input type="text" name="Name" value="" size="50"><br></h4>
<br>
<h4>1. Why is it important to think about safety?</h4>
<p><label for="q1"><input type="radio" name="1.1" value=" A" id="q1a" />it identifies where the risks are.</label></p>
<p><label for="q1"><input type="radio" name="1.1" value=" B" id="q1b" />because I may get hurt.</label></p>
<p><label for="q1"><input type="radio" name="1.1" value=" C" id="q1c" />because it may prevent accidents and keep everyone safe.</label></p>
<p><label for="q1"><input type="radio" name="1.1" value=" D" id="q1d"/>because it will keep others safe.</label></p>
<br>
<h4>11. Respirators should be used to prevent?</h4>
<input type="text" name="1.11" id="1.11" size= "120"></p>
<br>
<h4>12. Disposable gloves are optional but do provide a convenient way to avoid?</h4>
<input type="text" name="1.12" id="1.12" size= "120"></p>
<br>
<h4>13. Why should you prevent liquid oil and grease from entering the pores of your skin?</h4>
<input type="text" name="1.13" id="1.13" size= "120"></p>
<br>
<h4>14. Why shouldn't we use hot water to wash off grease and oil off our hands?</h4>
<input type="text" name="1.14" id="1.14" size= "120"></p>
<br>
<h4>15. List 3 things that may cause a fire or act as a fuel?</h4>
<p>a. <input type="text" name="1.15a" id="1.15a" size= "117"></p>
<p>b. <input type="text" name="1.15b" id="1.15b" size= "117"></p>
<p>c. <input type="text" name="1.15c" id="1.15c" size= "117"></p>
<input type="submit" value="Download">
</style>
<script language="Javascript" >
function download(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' +
encodeURIComponent(text));
pom.setAttribute('download', filename);
pom.style.display = 'none';
document.body.appendChild(pom);
pom.click();
document.body.removeChild(pom);
}
</script>