<input type="file" id="file-id" />
<input type="text" name="file_path" id="file-path">
在 jquery 中:
$("#file-path").val($("#file-id").val());
gives me : - 'C:\\fakepath\\test.py'
我正在使用 ubuntu
作为我的操作系统。如果我从 /home/mylappy/Document/test.py
选择一个文件,它会显示文件路径 'C:\\fakepath\\test.py'
最佳答案
For historical reasons, the value IDL attribute prefixes the filename with the string "C:\fakepath\". Some legacy user agents actually included the full path (which was a security vulnerability). As a result of this, obtaining the filename from the value IDL attribute in a backwards-compatible way is non-trivial. The following function extracts the filename in a suitably compatible manner: http://www.w3.org/TR/html5/number-state.html#file-upload-state
关于jquery - HTML 文件属性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4849024/