js操作文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta name="author" content="oscar999"> <title></title> <script> function handleFiles(files) { if(files.length) { var file = files[0]; var reader = new FileReader();
reader.readAsText(file);
reader.onload = function() { document.getElementById("filecontent").innerHTML = this.result; }; } } function handle(files){ if(files.length){ var file = files[0]; var reader = new FileReader(); reader.readAsText(file); reader.onload=function(){ document.getElementById('filecontent').innerHTML = this.result; } } } </script> </head> <body> <input type="file" id="file" onchange="handle(this.files)"/> <div id="filecontent"></div> </body> </html>