将Html5表单数据保存到文本文件。
问题描述:
我正在开发用于在html5中进行调查的移动网络应用程序。我需要将文件中的用户响应保存为csv格式。怎么办?我被困在存储部分..........请帮助我。
我不能将activex用于dat目的coz app需要在android + windows平板电脑上运行。
thanx提前。
i am developing mobile web app for conducting survey in html5. i need to save user responses in file preferably in csv format. How can do it? i am stuck with storing part.......... please please help me.
I cannot use activex for dat purpose coz app needs to work on android+ windows tablet.
thanx in advance.
答
这个 [ ^ ] help?
<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);
}
function addTextHTML()
{
document.addtext.name.value = document.addtext.name.value + ".html"
}
function addTextTXT()
{
document.addtext.name.value = document.addtext.name.value + ".txt"
}
</script>
<form name="addtext" onsubmit="download(this['name'].value, this['text'].value)">
<textarea rows="10" cols="70" name="text" placeholder="Type your text here:"></textarea>
<br>
<input type="text" name="name" value="" placeholder="File Name">
<input type="submit" onclick="addTextHTML();" value="Save As HTML">
<input type="submit" onclick="addTexttxt();" value="Save As TXT">
</form>