我希望单击选择文件按钮后显示所选图像的完整路径.关于如何做到这一点的任何想法?
I want the full path of a selected image to be displayed once Choose File button is clicked. Any idea on how to do that?
推荐答案除了执行两次POST之外,您还可以执行以下操作:
Instead of doing a double POST, you can do something like this:
function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e) { $('#blah').attr('src', e.target.result); } reader.readAsDataURL(input.files[0]); } } $("#imgInp").change(function() { readURL(this); });
<script src="ajax.googleapis/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="form1" runat="server"> <input type='file' id="imgInp" /> <img id="blah" src="#" alt="your image" /> </form>
请记住,仅因为您选择了要上传的文件并不意味着该文件已上传.服务器仍然没有收到数据,因此,从客户端收集数据要比我想做的要有意义.
Remember, that just because you've selected a file to upload doesn't mean its been uploaded. The server still hasn't received the data, thus, doing this on the client side makes a little more sense from what i gather you want to do.
(从以下地址窃取:在上传图片之前预览图片)