<h2>
<input type="file">
<img src="../img/a.png" id="one" alt>
</h2>
选择文件之后,根据文件来生成地址。这个url能够被对应的标签识别,把这个url的值赋给img的src。
$("input").on("change",function(){
//生成url
$("#one").attr("src",URL.createObjectURL(this.files[0]));
})
<h2>
<input type="file">
<img src="../img/a.png" id="one" alt>
</h2>
选择文件之后,根据文件来生成地址。这个url能够被对应的标签识别,把这个url的值赋给img的src。
$("input").on("change",function(){
//生成url
$("#one").attr("src",URL.createObjectURL(this.files[0]));
})