[英]Why is this code not alerting the text in the text file? (javascript/html)
Here is my code. 这是我的代码。 The problem is that the information isn't being alerted.
问题在于该信息未收到警报。 It worked in Js Fiddle but not on chrome/firefox/safari.
它在Js Fiddle中有效,但在chrome / firefox / safari中无效。 When I tried to use document.write to display the text in JsFiddle that didn't work either.
当我尝试使用document.write在JsFiddle中显示文本时,该文本也不起作用。 This code is giving me lots of problems.
这段代码给了我很多问题。
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
function readMultipleFiles(evt) {
//Retrieve all the files from the FileList object
var files = evt.target.files;
if (files) {
var r = new FileReader();
for (var i = 0, f; f = files[i]; i++) {
r.onload = (function(f) {
return function(e) {
var contents = e.target.result;
alert(contents);
};
})(f);
r.readAsText(f);;
}
} else {
alert("Failed to load files");
}
}
document.getElementById('fileinput').addEventListener('change', readMultipleFiles, false);
</script>
</head>
<body>
<input type="file" id="fileinput"/>
</body>
</html>
try 尝试
window.onload = function() {
document.getElementById('fileinput').addEventListener('change', readMultipleFiles, false);
}
Instead of just 不只是
document.getElementById('fileinput').addEventListener('change', readMultipleFiles, false);
Edit: So yeah, the solution was here 编辑:是的,解决方案在这里
execute chrome with chrome.exe --disable-web-security
for windows or google-chrome --disable-web-security
for linux. 对于Windows,使用
chrome.exe --disable-web-security
执行chrome;对于Linux,则使用google-chrome --disable-web-security
执行chrome。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.