我有这个代码。有人可以帮助我如何删除文件上传时的假路径吗?谢谢
html代码
<div id="file">Chose file</div>
<input type="file" name="file" style="display:none;"/>
jquery代码
var wrapper = $('<div/>').css({height:0,width:0,'overflow':'hidden'});
var fileInput = $(':file').wrap(wrapper);
fileInput.change(function(){
$this = $(this);
$('#file').text($this.val());
})
$('#file').click(function(){
fileInput.click();
}).show();
最佳答案
在 fileInput.change(function(){...})
中,您可以添加一些代码来更改 fakepath。例如,您可以从 fakepath 中获取文件名,如下所示:
var text = $('#file').html();
text = text.substring(text.lastIndexOf("\\") + 1, text.length);
$('#file').html(text);
您可以在此处查看示例:http://jsfiddle.net/cnfdcomg/
您可以避免创建 text
并直接将字符串传递给 html()
,如下所示:
$('#file').html("Your file is ready to be uploaded!");
希望对你有帮助!
关于html - 如何删除 jquery 文件上传中的 fakepath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30060853/