我想在页面里放一个小图片,单击的时候出现一个窗口正好显示图片的原始大小.最好有代码我是个初学者请说细点谢谢!!

解决方案 »

  1.   

    你说的窗口是弹出一个页面吗?
    window.open设他的width,height 为图片的大小就是
      

  2.   


    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script language="javascript">
    function GetImgSize(obj)
    {
    var BigImg=new Image()
    BigImg.src=obj.src
    return{w:BigImg.width,h:BigImg.height}
    }
    function ShowBigImg(obj)
    {
    var imgsizeTemp=GetImgSize(obj)
    alert(imgsizeTemp.w+imgsizeTemp.h)
    var imgboxTemp=document.createElement('div')
    imgboxTemp.id='imgbox'
    imgboxTemp.setAttribute('id','imgbox')
    document.body.appendChild(imgboxTemp)
    imgboxTemp=document.getElementById('imgbox')
    imgboxTemp.style.position='absolute'
    imgboxTemp.style.zIndex='1000'
    imgboxTemp.style.backgroundColor="#ddd"
    imgboxTemp.style.width=document.all?imgsizeTemp.w:imgsizeTemp.w+'px'
    imgboxTemp.style.height=document.all?imgsizeTemp.h:imgsizeTemp.h+'px'
    imgboxTemp.style.left=document.all?obj.offsetWidth:obj.offsetWidth+'px'
    imgboxTemp.style.top=document.all?obj.offsetHeight:obj.offsetHeight+'px'
    imgboxTemp.innerHTML="<img src='"+obj.src+"' />"
    }
    </script>
    </head>
    <body>
    <img src='http://image.ieche.com/8/1325/2007-7-12/8G4244K2DD8KHHH1H8.jpg' width='60px' height='60px' onclick='ShowBigImg(this)' />
    </body>
    </html>