日期:2014-05-16  浏览次数:20353 次

来者有分,超级郁闷中,javascript代码如何改变<img>的尺寸大小,在线急
如题,我用
document.getElementById("Img1").width=100;
document.getElementById("Img1").height=100;

好像都改变不了,不知道是怎么回事,请各位给予回答,谢谢!

------解决方案--------------------
var dd=document.getElementById("Img1");
dd.style.width='100px';
dd.style.height='100px';

试试吧。。。
------解决方案--------------------
document.getElementById("Img1").style.width=100; 
document.getElementById("Img1").style.height=100; 

------解决方案--------------------
HTML code

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>未命名頁面</title>
    
<script language="javascript" type="text/javascript">
// <!CDATA[

function Button1_onclick() {
document.getElementById('img1').style.height=30;
document.getElementById('img1').style.width=30;
}

// ]]>
</script>
</head>
<body>
    <form id="form1" runat="server">
    <img id="img1" src="Image/P2P_1.jpg"/>
        <input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />
    
    </form>
</body>
</html>

------解决方案--------------------
document.getElementById("Img1").style.width=100;
document.getElementById("Img1").style.height=100;
------解决方案--------------------
没问题啊,不过最好是设置style中的width和height

HTML code
<html>
<head>
<title></title>
</head>
<body>
<input type='button' onclick='setSize()' value='重新设置'/><br/>
<script>
function setSize()
{
  var im=document.getElementById("img1");
  im.width=100;
  im.height=100;
}
</script>
<img id='img1' src='xx1.gif'/>
</body>
</html>