如何使用Jquery直接导入记事本的内容
直接上代码
<!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>
(本人微信号:Liberty-bcy)如果,你正在埋怨命运不眷顾,那请记住:命,是失败者的借口;运,是成功者的谦词。