使用URL.createObjectURL图片选择预览

<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]));

})

猜你喜欢

转载自blog.csdn.net/qq_34559257/article/details/80309919