如何使用 jQuery 在 div 中显示图像?我有这段代码,但它不起作用。
$(document).ready(function () {
$("#up").click(function () {
var imgUrl = $("img_input").val();
$("#imageDiv").prop("src", imgUrl).show();
});
});
其中 up
是指定给以下内容的 id
:
<input id="img_input" type="file">
<button id="up">
最佳答案
更改:
$("img_input").val();
至
$("#img_input").val();
如果imageDiv
是div
的id并且图像存在于其中,则执行:
$("#imageDiv").find("img").prop("src", imgUrl).show();
关于jquery - 使用 jquery 选择后在 div 中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14707209/