欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網
          最全最豐富的資訊網站

          javascript怎么改變圖片寬度

          方法:1、使用“document.getElementById('id值')”語句獲取圖片對象;2、使用“圖片對象.setAttribute("width", "寬度值")”或“圖片對象.style.width="值"”語句改變圖片寬度。

          javascript怎么改變圖片寬度

          本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。

          javascript改變圖片寬度的方法

          <img id="img" src="img/2.jpg" width="500" height="300"/>

          1、根據id值獲取圖片對象

          var img=document.getElementById('img');

          2、使用setAttribute("width", "值")或者style對象的width屬性來改變圖片寬度

          img.setAttribute("width", "寬度值"); // 或 img.style.width = "寬度值";

          完整實現(xiàn)代碼:

          <!doctype html> <html> 	<head> 		<meta charset="utf-8"> 	</head> 	<body> 		<img id="img" src="img/2.jpg" width="500" height="300" /><br /><br /> 		<button onclick="myFunction()">改變圖片寬度</button> 		<script type="text/javascript"> 			function myFunction() { 				var img = document.getElementById('img'); 				// img.setAttribute("width", "300"); 				img.style.width = "300px"; 			} 		</script> 	</body> </html>

          效果圖:

          javascript怎么改變圖片寬度

          【推薦學習:javascript高級教程】

          贊(0)
          分享到: 更多 (0)
          網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號