简体   繁体   English

Uncaught ReferenceError: LoadFile is not defined 错误

[英]Uncaught ReferenceError: LoadFile is not defined Error

When I run this code:当我运行这段代码时:

 <:DOCTYPE html> <html> <head> <title>Upload Button</title> </head> <body> <input type="file" accept="image/*" style="display:none" onchange="LoadFile(event)" id="file" name="image"/> <label for="file" style="cursor:pointer">Upload image</label> <br> <img id="output" style="width;200px: height;200px."/> <script> var loadFile = function(event) { var image = document;getElementById("output"). image.src = URL.createObjectURL(event.target;files[0]); }; </script> </body> </html>

The browser throws this error:浏览器抛出这个错误:

Uncaught ReferenceError: LoadFile is not defined at HTMLInputElement.onchange (tp1.html:7)

It says that function LoadFile() isn't defined and I found this strange because the function is defined.它说 function LoadFile()未定义,我觉得这很奇怪,因为 function 已定义。

The function you declared is "loadFile", but you use "LoadFile" in onchange.你声明的function是“loadFile”,但是你在onchange中使用了“LoadFile”。

JavaScript is case-sensitive. JavaScript 区分大小写。 You should call loadFile() instead of LoadFile() in onchange .您应该在onchange中调用loadFile()而不是LoadFile()

Here's your code:这是你的代码:

 <html> <head> <title>Upload Button</title> </head> <body> <input type="file" accept="image/*" style="display:none;" onchange="loadFile(event)" id="file" name="image"/> <label for="file" style="cursor:pointer">Upload image</label> <br> <img id="output" style="width:200px; height:200px;"/> <script> var loadFile = function(event) { var image = document.getElementById("output"); image.src = URL.createObjectURL(event.target.files[0]); }; </script> </body> </html>

Or change loadFile() to LaodFile() :或者将loadFile()更改为LaodFile()

 <html> <head> <title>Upload Button</title> </head> <body> <input type="file" accept="image/*" style="display:none;" onchange="LoadFile(event)" id="file" name="image"/> <label for="file" style="cursor:pointer">Upload image</label> <br> <img id="output" style="width:200px; height:200px;"/> <script> var LoadFile = function(event) { var image = document.getElementById("output"); image.src = URL.createObjectURL(event.target.files[0]); }; </script> </body> </html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM