上传图片即时显示<input type="file" />(兼容所有浏览器)

来源:互联网 发布:一切用数据说话 编辑:程序博客网 时间:2024/05/20 03:38

$(function(){    $("#image").change(function (){var reader = new FileReader();        reader.readAsDataURL(this.files[0]);        setTimeout(function() {            //设置延时,否则取不到result值    $("#img").attr("src",reader.result);        }, 100);    });});
以上是js处理代码。

<img align="center" src="/image/yjz.png" height="240" alt="浏览器不支持" id="img"/><form action="" method="post" enctype="multipart/form-data">    <input id="image" type="file" accept="image/gif, image/jpeg, image/png" name="file" /></form>
以上是html代码。

0 0
原创粉丝点击