久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網
      最全最豐富的資訊網站

      javascript怎么設置元素寬度

      javascript設置元素寬度的方法:首先使用“document.getElementById("id值")”語句獲取元素對象;然后使用“元素對象.style.width="寬度值"”語句來設置元素的寬度。

      javascript怎么設置元素寬度

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

      javascript設置元素寬度

      原理:

      • 獲取元素對象

      • HTML DOM Style 對象的width 屬性設置元素的寬度。

      代碼示例:

      <!DOCTYPE html> <html>  	<head> 		<meta charset="UTF-8"> 		<style> 			img { 				width: 200px; 			} 		</style> 	</head>  	<body> <img id="img" src="img/1.jpg" />  <p id="demo">img圖片寬度為200px。</p>  <button onclick="myFunction()">設置img圖片的寬度</button>  <script> 	function myFunction() { 		document.getElementById("img").style.width="300px"; 		document.getElementById("demo").innerHTML="img圖片寬度為300px。"; 	} </script> 	</body>  </html>

      效果圖:

      javascript怎么設置元素寬度

      說明:

      Style 對象的width 屬性可以設置元素的寬度。

      語法:

      Object.style.width=auto|length|%
      描述
      auto 默認。瀏覽器可計算出實際的寬度。
      % 定義基于其包含塊的百分比寬度。
      length 使用 px、cm 等單位定義寬度。

      查找元素的方法:

      1.根據(jù)id獲取元素

      document.getElementById("id屬性的值");

      2.根據(jù)標簽名字獲取元素

      document.getElementsByTagName("標簽的名字");

      3.根據(jù)name屬性的值獲取元素

      document.getElementsByName("name屬性的值");

      4.根據(jù)class屬性獲取元素

      document.getElementsByClassName("類樣式的名字");

      5.根據(jù)css路徑獲取元素 (獲取一個)

      document.querySelector("css路徑");

      6.根據(jù)css路徑獲取元素 (獲取一組)

      document.querySelectorAll("css路徑");

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

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