js 上传图片格式判断的问题 20
<script>varimg=null;functions(){if(img)img.removeNode(true);img=document.createElemen...
<script>
var img=null;
function s()
{
if(img)img.removeNode(true);
img=document.createElement("img");
img.style.position="absolute";
img.style.visibility="hidden";
img.attachEvent("onreadystatechange",orsc);
img.attachEvent("onerror",oe);
document.body.insertAdjacentElement("beforeend",img);
img.src=inp.value;
}
function oe()
{
alert("cant load img");
btn.disabled=true;
}
function orsc()
{
if(img.readyState!="complete")return false;
alert("图片大小:"+img.offsetWidth+"X"+img.offsetHeight);
alert("图片尺寸:"+img.fileSize);
btn.disabled=false;
}
</script>
<form enctype=multipart/form-data method=post action="">
<input id=inp type="file" onpropertychange="s()">
<br>
<button id=btn disabled>UpLoad</button>
</form>
为何在按钮外加了<form>标签,js的函数就不能正常执行了,而把<form>去了就可以正常执行,难道是onpropertychange和form有冲突吗?
我还要取得表单里的数据的,放到外面怎么取呢? 展开
var img=null;
function s()
{
if(img)img.removeNode(true);
img=document.createElement("img");
img.style.position="absolute";
img.style.visibility="hidden";
img.attachEvent("onreadystatechange",orsc);
img.attachEvent("onerror",oe);
document.body.insertAdjacentElement("beforeend",img);
img.src=inp.value;
}
function oe()
{
alert("cant load img");
btn.disabled=true;
}
function orsc()
{
if(img.readyState!="complete")return false;
alert("图片大小:"+img.offsetWidth+"X"+img.offsetHeight);
alert("图片尺寸:"+img.fileSize);
btn.disabled=false;
}
</script>
<form enctype=multipart/form-data method=post action="">
<input id=inp type="file" onpropertychange="s()">
<br>
<button id=btn disabled>UpLoad</button>
</form>
为何在按钮外加了<form>标签,js的函数就不能正常执行了,而把<form>去了就可以正常执行,难道是onpropertychange和form有冲突吗?
我还要取得表单里的数据的,放到外面怎么取呢? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询