客户端JS验证图片上传的问题!大家帮帮忙!
获取上传图片的尺寸:
//检查插入是否为图片
var img=null;
function chkimg(inp)
{
if(img)img.removeNode(true);
img=document.getElementById("imgShow");
img.attachEvent("onreadystatechange",isimg);
img.attachEvent("onerror",notimg);
img.src=inp;
}
function notimg()
{
alert("Can't load image,try again!");
}
function isimg()
{
alert("图片大小" + Math.round(img.fileSize/1024) +"KB\r图片宽度"+ img.style.width +"\r图片高度"+ img.offsetHeight);
}
哪里有错?
------解决方案--------------------if(img)img.removeNode(true);
--
你都移除了 ,还怎么显示呢?
------解决方案-------------------- //检查插入是否为图片
var img=null;
function chkimg(inp)
{
img=document.getElementById("imgShow");
img.src=inp;
isimg();
}
function notimg()
{
document.getElementById("imgShow").src="../../property/property_img/default.jpg"
document.getElementById("txtImageSize").value='noimage';
}
function isimg()
{
var noimage=document.getElementById("txtImageSize").value;
noimage= img.offsetWidth +"x"+ img.offsetHeight;
}
<asp:Image ID="imgShow" runat="server" Height="300px" Width="400px" AlternateText="Can't find a photo" onerror="notimg()" />
<asp:FileUpload ID="myUlf" runat="server"/>
<asp:LinkButton ID="btnUp" runat="server" OnClientClick="chkimg(myUlf.value)" OnClick="btnUp_ServerClick">Upload</asp:LinkButton>
为什么点了上传,显示了上传图片的尺寸后,又立马执行了notimg();