js实现图片上传的预览效果
来源:互联网 发布:sqlserver聚合函数 编辑:程序博客网 时间:2024/06/10 09:46
见代码:
上传图片示例:
html:
<img src="" id="img1" class="img-responsive" alt="Cinque Terre" style="display:none;" width="100px" height="100px"> <input type="file" id="input1" onchange="preview(1)" name="icon">
js:
<script type="text/javascript">//上传图片前先显示出来function preview(id){ var file = document.getElementById('input'+id).files[0]; var url ; if (window.createObjectURL!=undefined) { // basic url = window.createObjectURL(file) ; } else if (window.URL!=undefined) { // mozilla(firefox) url = window.URL.createObjectURL(file) ; } else if (window.webkitURL!=undefined) { // webkit or chrome url = window.webkitURL.createObjectURL(file) ; } document.getElementById("img"+id).src=url; if(url){ document.getElementById("img"+id).style.display="block";}}</script>
html:
<img src="xxx" id="img1" class="img-responsive" alt="Cinque Terre" width="100px" height="100px"> <input type="file" id="input1" onchange="preview(1)" name="icon">
js:
<script type="text/javascript">//上传图片前先显示出来function preview(id){ var file = document.getElementById('input'+id).files[0]; var url ; if (window.createObjectURL!=undefined) { // basic url = window.createObjectURL(file) ; } else if (window.URL!=undefined) { // mozilla(firefox) url = window.URL.createObjectURL(file) ; } else if (window.webkitURL!=undefined) { // webkit or chrome url = window.webkitURL.createObjectURL(file) ; } document.getElementById("img"+id).src=url; }</script>
注:
注意image和input两个标签id值的特点,js是根据id值来绑定的
阅读全文
0 0
- js实现图片上传的预览效果
- js实现图片上传前预览效果
- JS上传图片预览效果
- js实现上传时图片的预览
- JS实现图片的上传和预览
- js实现图片上传预览的功能
- js实现上传图片预览的方法
- js实现上传图片的及时预览
- js 实现图片上传之前的预览
- js实现图片上传预览
- js实现图片上传预览
- js实现图片上传预览
- js实现图片上传预览
- js上传图片预览实现
- js实现图片上传预览
- js实现图片上传预览
- [JS]实现图片上传预览
- JS实现兼容IE6、IE7、IE8的图片上传前预览效果
- leetcode--Valid Palindrome
- How to design DL model(1):Efficient Convolutional Neural Networks for Mobile Vision Applications
- SpringBoot学习——websocket组件学习在线聊天室demo
- CodeForces 327 C.Magic Five(快速幂)
- 脱标流下的css定位 及其引发的思考总结
- js实现图片上传的预览效果
- 技术点-hibernate关系映射-一对一映射
- poj2229
- 初识KnockoutJS
- Android Bitmap大量使用不产生OOM之“加载大图片资源优化”
- windows下编译openssl
- 解决Android 5.1物理键盘与软键盘的同时使用
- JAVA定时器Timer的使用
- Java学习总结之基本语法