html部分
1 | <form> |
js
为了美观所以上面对input的file进行隐藏,然后我们写入js1
2
3
4
5
6
7
8
9
10
11
12
13function getObjectURL(file) {
var url = null ;
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);
} else {
alert("该浏览器不能实现预览功能!");
}
return url;
}
这里主要是用getObjectURL获取的,然后兼容一下各个浏览器,除了IE8,然后我们调用一下.
图片上传
1 | $("#face").click(function () { |
show

还有就是函数结合createRange,实现上传图片的预览,这里就暂不详述了.