我在百度找了好几个,可是有的浏览器就显示不了,比如:IE7、FF、Opera都不行,我在搜狗最新版测试就可以显示,调到兼容模式就不行了,我用的代如下:
<%-- <script type="text/javascript">
var allowExt = ['jpg', 'gif', 'bmp', 'png', 'jpeg'];
var preivew = function(file, container){
try{
var pic = new Picture(file, container);
}catch(e){
alert(e);
}
}
//缩略图类定义
var Picture = function(file, container){
var height = 0,
widht = 0,
ext = '',
size = 0,
name = '',
path = '';
var self = this;
if(file){
name = file.value;
if (window.navigator.userAgent.indexOf("MSIE")>=1){
file.select();
path = document.selection.createRange().text;
}else if(window.navigator.userAgent.indexOf("Firefox")>=1){
if(file.files){
path = file.files.item(0).getAsDataURL();
}else{
path = file.value;
}
}
}else{
throw "bad file";
}
ext = name.substr(name.lastIndexOf("."), name.length);
if(container.tagName.toLowerCase() != 'img'){
throw "container is not a valid img label";
container.visibility = 'hidden';
}
container.src = path;
container.alt = name;
container.style.visibility = 'visible';
height = container.height;
widht = container.widht;
size = container.fileSize;
this.get = function(name){
return self[name];
}
this.isValid = function(){
if(allowExt.indexOf(self.ext) !== -1){
throw 'the ext is not allowed to upload';
return false;
}
}
}
</script> --%>
<form id="form1" runat="server">
<div class='previewDemo'>
<input id="file" type="file" onchange="preivew(this, document.getElementById('img'));">
<img id="img" style="visibility:hidden" mce_style="visibility:hidden" height="100px" width="100px">
</div> </form> 你们帮我看下是不是改哪里就可以兼容了,或者你有兼容的代码就分享下,谢谢各位大侠了。
<%-- <script type="text/javascript">
var allowExt = ['jpg', 'gif', 'bmp', 'png', 'jpeg'];
var preivew = function(file, container){
try{
var pic = new Picture(file, container);
}catch(e){
alert(e);
}
}
//缩略图类定义
var Picture = function(file, container){
var height = 0,
widht = 0,
ext = '',
size = 0,
name = '',
path = '';
var self = this;
if(file){
name = file.value;
if (window.navigator.userAgent.indexOf("MSIE")>=1){
file.select();
path = document.selection.createRange().text;
}else if(window.navigator.userAgent.indexOf("Firefox")>=1){
if(file.files){
path = file.files.item(0).getAsDataURL();
}else{
path = file.value;
}
}
}else{
throw "bad file";
}
ext = name.substr(name.lastIndexOf("."), name.length);
if(container.tagName.toLowerCase() != 'img'){
throw "container is not a valid img label";
container.visibility = 'hidden';
}
container.src = path;
container.alt = name;
container.style.visibility = 'visible';
height = container.height;
widht = container.widht;
size = container.fileSize;
this.get = function(name){
return self[name];
}
this.isValid = function(){
if(allowExt.indexOf(self.ext) !== -1){
throw 'the ext is not allowed to upload';
return false;
}
}
}
</script> --%>
<form id="form1" runat="server">
<div class='previewDemo'>
<input id="file" type="file" onchange="preivew(this, document.getElementById('img'));">
<img id="img" style="visibility:hidden" mce_style="visibility:hidden" height="100px" width="100px">
</div> </form> 你们帮我看下是不是改哪里就可以兼容了,或者你有兼容的代码就分享下,谢谢各位大侠了。
解决方案 »
- 关于jquery控制多个DIV显示隐藏的问题
- 页面定时刷新问题
- Jquery的问题
- [新手提问]javascript:前缀.
- 如何在javascript中旋转图片?
- <p style="color=red"> 关于html中背景音乐的设置问题!!!请教大侠!(急) </p>
- 怎么样从表单中删除一个控件?
- (100分)急用:请帮我修改一下网页对联式广告的代码.将四个广告中在同一方的两个广告隔开一段距离.
- 有什么办法可以获取客户端的分辨率?
- window.location="test6.html?id=i3 到test6页面后我怎么取出这个id?
- 行路 求教HTML5 audio 中的ended事件问题。
- 在线等答案。。。。。求高人
在火狐7.0以下版本中使用如下代码获取上传图片全路径:obj.files.item(0).getAsDataURL(),obj为文件对象。但是在7.0以上的版本中会报错,若使用 window.URL.createObjectURL(obj.files.item(0)) 即可解决。
客户端图片,完全没必要。
现在AJAX这么方便不用,真是浪费。传到服务器取服务器上的就行了。