Javascript文件变量声明/创建错误:此对象不支持此操作
问题描述:
今天我创建了一个html文档。编码登录和注册网站。我的想法如下: 当你创建一个帐户时,你的数据应该保存在一个文本文件中(不安全)。 登录时,代码应该将输入与文件中的数据进行比较。 但是,当我想为我的文件初始化变量时,Internet Explorer显示以下错误:SCRIPT445:此对象不支持此操作。 标记线我这里有:Javascript文件变量声明/创建错误:此对象不支持此操作
//Here is the layout creation...
<script>
function login()
{
var username = document.getElementById("txtusername").value;
var kennwort = document.getElementById("txtpassword").value;
}
function register()
{
var rusername = document.getElementById("txtrusername").value;
var remail = document.getElementById("txtremail").value;
var rkennwort = document.getElementById("txtrpassword").value;
var rconfirmpassword = document.getElementById("txtrconfirmpassword").value;
if(rpassword!=rconfirmpassword)
{
alert(unescape("The passwords do not match!", "Error"));
return;
}
//This line creates the error
var file = new File("C:/Users/Konsicoder/Desktop/Data/data.txt");
//This line creates the error
alert("Success!", "Success");
}
</script>
答
代替提供本地文件系统路径和实例化一个File对象,你可能需要使用浏览器文件选择器能够首先获得一个句柄的本地文件。
[http://www.html5rocks.com/en/tutorials/file/dndfiles/][1] [使用文件API] [1]
这里是SO提供有关File对象如何被实例化的细节后JavaScript读取文件: How to instantiate a File object in JavaScript?
+0
请参阅?当某人将解决方案与答案中的某些内容联系起来时,就是这个问题。它消失了。泡芙,这个问题没有更多的解决方案。 – GustavoCinque
''//不是HTML中的评论。 –