jquery - HTML 文件属性问题

标签 jquery html linux ubuntu

<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/

相关文章:

javascript - 在 squeeze 上安装 node-js 最新版本的问题

c - Mac OSX 上的 mmapping/dev/zero 提供无效参数

javascript - 使用 jQuery 插入列表项的问题

javascript - jQuery 不隐藏 div

html - 将边框间距应用于某些单元格

html - 悬停后更改背景颜色并保留父图像

python - 有没有一种简单的方法可以将 <pre> 标签的内容获取到 pandas 数据帧?

linux - gnu screen 不要改变我的窗口标题

javascript - 像 jQuery 的 .click() 一样工作的 CSS3 选择器?

javascript - 为什么不同的灯箱链接打开的内容总是相同?