这段代码在ie6.0运行没问题,但到ie7.0下好像运行到img=document.createElement("img")就不好使了 感觉好像没办法创建img对象,请各位看看,解决就给分谢谢
<script>
var img=null;
function sc(){
//判断浏览器及版本
var ua=navigator.userAgent;
var ie=false;
if(navigator.appName=="Microsoft Internet Explorer"){
ie=true;}
if(!ie){
form.file.outerHTML=form.file.outerHTML.replace(/value=\w/g,'');
alert("建议你使用IE6。0以上的浏览器,在非IE浏览器中上传功能不能正常使用。");
return;}
var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))));
if(IEversion< 6.0){
form.file.outerHTML=form.file.outerHTML.replace(/value=\w/g,'');
alert("系统检测到你的浏览器的版本比较低,建议你使用IE6。0以上的浏览器,否则上传功能不能正常使用。\n你可以http://www.microsoft.com/china/免费获得IE的最新版本!");
return;}
//判断是否图片 inp为文本框id
form.btn.disabled=true;
if(img)img.removeNode(true);
img=document.createElement("img"); //创建img对象
img.style.position="absolute";
img.style.visibility="hidden";
img.attachEvent("onreadystatechange",orsc);
img.attachEvent("onerror",oe);
document.body.insertAdjacentElement("beforeend",img);
img.src=form.inp.value;}
function oe(){
//不是图片显示错误信息
alert("对不起,只能上传图片文件!");
form.file.outerHTML=form.file.outerHTML.replace(/value=\w/g,'');}
function orsc(){
//取得图片信息
var t
if(img.readyState!="complete")return false;
t=img.fileSize
form.img_s.value=t //这是filesize
if (t><%=sc_dx*1024%>) {
alert("对不起,上传图片不能超过指定大小<%=sc_dx%>kb!");
form.file.outerHTML=form.file.outerHTML.replace(/value=\w/g,'');
return false;}
form.btn.disabled=false;}
</script>
<form name="form" method="post" action="?chuan=yes" enctype="multipart/form-data" >
<input name="file" type="file" class="wenbenkuang" size="30" id="inp" onChange="sc()">
<input name="Submit" type="submit" class="wenbenkuang" value="上传" id=btn disabled="disabled"><input name="img_s" type="hidden" id="img_s">
</form>
俺在 IE 7 下测试正常,上传按钮完全可用!页面名称:testPicUpload.html代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head> <body>
<script>
var img=null;
function sc(){
//判断浏览器及版本
var ua=navigator.userAgent;
var ie=false;
if(navigator.appName=="Microsoft Internet Explorer"){
ie=true;}
if(!ie){
form.file.outerHTML=form.file.outerHTML.replace(/value=\w/g,'');
alert("建议你使用IE6。0以上的浏览器,在非IE浏览器中上传功能不能正常使用。");
return;}
var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))));
if(IEversion< 6.0){
form.file.outerHTML=form.file.outerHTML.replace(/value=\w/g,'');
alert("系统检测到你的浏览器的版本比较低,建议你使用IE6。0以上的浏览器,否则上传功能不能正常使用。\n你可以http://www.microsoft.com/china/免费获得IE的最新版本!");
return;}
//判断是否图片 inp为文本框id
form.btn.disabled=true;
if(img)img.removeNode(true);
img=document.createElement("img"); //创建img对象
img.style.position="absolute";
img.style.visibility="hidden";
img.attachEvent("onreadystatechange",orsc);
img.attachEvent("onerror",oe);
document.body.insertAdjacentElement("beforeend",img);
img.src=form.inp.value;}
function oe(){
//不是图片显示错误信息
alert("对不起,只能上传图片文件!");
form.file.outerHTML=form.file.outerHTML.replace(/value=\w/g,'');}
function orsc(){
//取得图片信息
var t
if(img.readyState!="complete")return false;
t=img.fileSize
form.img_s.value=t //这是filesize
if (t>99999) {
alert(t);
alert("对不起,上传图片不能超过指定大小<%=sc_dx%>kb!");
form.file.outerHTML=form.file.outerHTML.replace(/value=\w/g,'');
return false;}
form.btn.disabled=false;}
</script>
<form name="form" method="post" action="?chuan=yes" enctype="multipart/form-data" >
<input name="file" type="file" class="wenbenkuang" size="30" id="inp" onChange="sc()">
<input name="Submit" type="submit" class="wenbenkuang" value="上传" id=btn disabled="disabled"><input name="img_s" type="hidden" id="img_s">
</form>
</body>
</html>
这个在IE7下上是可用的吧
你要是有错误,不一定是这个问题啊