如何使用javascript或jquery从计算机读取文件 [英] How to read a file from computer using javascript or jquery
问题描述
朋友们,
我有一个浏览按钮,它正在计算机中搜索文件,当我单击确定"时,它显示路径的代码,但仅带有伪路径.但是我想读取我正在浏览的文件的内容以及该代码将粘贴到某些编辑器中.我已使用jquery代码获取文件的路径.
代码:
Hi friends,
I have an browse button it is searching for files in the computer and when i clicking ok it is displaying the code of the path but only with fake path.but i want to read the content of the file that i am browsing and the content of the code will be pasted in to some editor.I have used the jquery code to get the path of the file.
Code:
var paths = '';
$('input[type=file]').each(function () {
paths = paths + $(this).val();
});
alert(paths);
它使用伪路径(例如c:/fakepath/new.docx)显示文件的路径
获取路径后,我想读取doc文件的内容,然后将代码粘贴到编辑器中,任何机构都可以帮助我
我正在使用jquery和javascript
为您添加
It is displaying the path of the file with fake path like c:/fakepath/new.docx
after getting the path i want to read the content of the doc file and then i want to paste the code in to the editor can any body help me
I am using jquery and javascript
Thaking you
推荐答案
(' input [type = file ]').each(function(){ 路径=路径+
('input[type=file]').each(function () { paths = paths +
( this ).val(); }); alert(paths);
(this).val(); }); alert(paths);
它使用伪路径(例如c:/fakepath/new.docx)显示文件的路径
获取路径后,我想读取doc文件的内容,然后将代码粘贴到编辑器中,任何机构都可以帮助我
我正在使用jquery和javascript
解冻
It is displaying the path of the file with fake path like c:/fakepath/new.docx
after getting the path i want to read the content of the doc file and then i want to paste the code in to the editor can any body help me
I am using jquery and javascript
Thaking you
如果您可以将完整路径(c:/fakepath/new.docx
)读入变量,哪里有问题?
使用替换方法 [
If you can read full path (c:/fakepath/new.docx
) into variable, where is a problem?
Use replace method[^] and replace "/" with "\" ;)
这篇关于如何使用javascript或jquery从计算机读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!