我想获取我选择的图像的完整路径,但问题是我选择图像后没有出现图像。
请帮帮我:)
这是我的代码。
JavaScript
<script type="text/javascript">
function imgchange()
{
var filePath = $('#file').val();
$("#imgs").attr('src',filePath);
}
</script>
HTML
<form action="#" method="post" enctype="multipart/form-data">
<center>
<table>
<tr>
<td colspan="2"><center><img id="imgs" width="170px" height="160px" ></img></center></td>
</tr>
<tr>
<td align="right"><b><label for="file">Filename:</label></b></td><td><input type="file" name="file" id="file" onchange="imgchange()"></td>
</tr>
</table>
</center>
<div class="buttons_save">
<button class="buttons_profile3" id="btnSubmit" >SAVE</button>
</div>
</form>
最佳答案
演示:- JSFIDDLE
试试这个:
这是 HTML 代码:-
<input type="file" id="i_file" value="">
<input type="button" id="i_submit" value="Submit">
<br>
<img src="" width="200" style="display:none;" />
这是 JS:-
$('#i_file').change( function(event) {
$("img").fadeIn("fast").attr('src',URL.createObjectURL(event.target.files[0]));
});
关于javascript - 使用 javascript 获取完整图像路径并放入 img src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22293023/