上传图片即时显示
2015-07-09 15:58
295 查看
//图片即时显示
/**
* 获取图片路径
*/
function geturl(file) {
var url = null;
if (window.createObjectURL != undefined) {
url = window.createObjectURL(file);
} else if (window.URL != undefined) {
url = window.URL.createObjectURL(file);
} else if (window.webkitURL != undefined) {
url = window.webkitURL.createObjectURL(file);
}
return url;
}
$(function(){
$("#articleImage").change(function(){
var image = $("#articleImage")[0];
var url = geturl(image.files[0]);
if(url == null){
$("#showImage").hide();
}else{
$("#showImage").show();
$("#showImage").attr("src",url);
}
});
});
<label>图片:</label>
<input type="file" id="articleImage" name="articleImage" >
<img id="showImage" src="">
/**
* 获取图片路径
*/
function geturl(file) {
var url = null;
if (window.createObjectURL != undefined) {
url = window.createObjectURL(file);
} else if (window.URL != undefined) {
url = window.URL.createObjectURL(file);
} else if (window.webkitURL != undefined) {
url = window.webkitURL.createObjectURL(file);
}
return url;
}
$(function(){
$("#articleImage").change(function(){
var image = $("#articleImage")[0];
var url = geturl(image.files[0]);
if(url == null){
$("#showImage").hide();
}else{
$("#showImage").show();
$("#showImage").attr("src",url);
}
});
});
<label>图片:</label>
<input type="file" id="articleImage" name="articleImage" >
<img id="showImage" src="">
相关文章推荐
- 双绞线测试的参数主要有哪些?
- ECNUOJ 2150 完美的拯救
- 【Spring-AOP-学习笔记-4】@After后向增强处理简单示例
- [LeetCode] Maximum Gap
- PowerDesigner 15.1 安装步骤详细图解及破解
- 论运维工程师,系统工程师,系统架构师的区别
- 通过iptables防止暴力破解ssh
- C# 委托系列(二)将方法绑定到委托
- leveldb性能调优
- 新手入门程序必须克服的5个障碍
- Net4.0的网站在IE10、IE11出现“__doPostBack未定义”的解决办法。
- ProE/Creo插件 MCADEx Tools 4.1
- nginx代理websocket协议
- 代码农民从做事情的经验
- 实现背景的变色动画
- 老僧长谈设计模式-1-单例模式
- 1014--Hibernate 检索方式--概述
- Android自定义控件
- centos 64bit 安装与升级 chrome的方法
- iOS 启动图相关