直接上代码
<!DOCTYPE html><html><head> ???<title> ???</title></head><body> ???jsReadFile:<input type="file" onchange="jsReadFiles(this.files)" /> ???<button onclick="jsReadFiles();">read</button></body></html><script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script><script> ???//js 读取文件 ???function jsReadFiles(files) { ???????if (files.length) { ???????????var file = files[0]; ???????????var reader = new FileReader();//new一个FileReader实例 ???????????if (/text+/.test(file.type)) {//判断文件类型,是不是text类型 ???????????????reader.onload = function () { ???????????????????$(‘body‘).append(‘<pre>‘ + this.result + ‘</pre>‘); ???????????????} ???????????????reader.readAsText(file); ???????????} ???????????else { ???????????????alert("请选择文本文件"); ???????????????return false; ???????????} ???????????//else if (/image+/.test(file.type)) {//判断文件是不是imgage类型 ???????????// ???reader.onload = function () { ???????????// ???????$(‘body‘).append(‘<img src="‘ + this.result + ‘"/>‘); ???????????// ???} ???????????// ???reader.readAsDataURL(file); ???????????//} ???????} ???}</script>
如何使用Jquery直接导入记事本的内容
原文地址:https://www.cnblogs.com/LoveQin/p/8367736.html