javasript 实现file图片预览

<cript type="text/javacript">
function changeFile(){
var Outid=document.getElementById('imgout');
Outid.src=document.getElementById('title_picture').value;
var Nimg=new Image();
Nimg.src =document.getElementById('title_picture').value;

Outid.height=Nimg.height;
Outid.width=Nimg.width;

if(Nimg.height != 110 || Nimg.width != 110){
alert("上传图片大小必须为:200x150,请重新选择图片!");
Outid.style.display='none';
document.getElementById('title_picture').value='';
}else{
Outid.style.display='block';
}
}
</cript>


   
<div id="picture_confirm" align="left">
<tr height=30>
    <td width="10%" height="35" class="boxHead" nowrap><b>发布为图片标题:</b></td>
    <td background="../images/leftbg2.gif" align='left' colspan="3">
    <input type="file" id="title_picture" name="title_picture" size="35" value="" onchange="changeFile();"><font color="red">    注:请上传(110*110)的图片!</font>
    </td>
   </tr> 
   
<tr>
<td width="10%" height="35" class="boxHead" nowrap><b>预览:</b></td>
<td background="../images/leftbg2.gif" align='left' colspan="3"><img src="" id="imgout" border="1" style="display:none;" /></td>
</tr>
</div>

 

你可能感兴趣的:(javasript)