<html> <body> <p>选择要加载的文件:</p> <input id="inputFileToLoad" type="file" onchange="loadImageFileAsURL();" /> <p>文件内容为DataURL:</p> <textarea id="textAreaFileContents" style="width:640;height:240" ></textarea> <script type="text/javascript"> function loadImageFileAsURL() { var filesSelected = document.getElementById("inputFileToLoad").files; if (filesSelected.length > 0) { var fileToLoad = filesSelected[0]; var fileReader = new FileReader(); fileReader.onload = function(fileLoadedEvent) { var textAreaFileContents = document.getElementById ( "textAreaFileContents" ); textAreaFileContents.innerHTML = fileLoadedEvent.target.result; }; fileReader.readAsDataURL(fileToLoad); } } </script> </body> </html>
评论已关闭!