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

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

          javascript怎么修改元素的style屬性

          在javascript中,可以利用setAttribute()方法來修改style屬性,該方法可以為一個已存在的指定屬性修改屬性值,語法“元素對象.setAttribute("style","樣式代碼");”。

          javascript怎么修改元素的style屬性

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

          在javascript中,可以利用setAttribute()方法來修改style屬性。

          setAttribute() 方法添加指定的屬性,并為其賦指定的值。如果這個指定的屬性已存在,則僅設(shè)置/更改值。

          語法:

          element.setAttribute(attributename,attributevalue)
          參數(shù) 類型 描述
          attributename String 必需。您希望添加的屬性的名稱。
          attributevalue String 必需。您希望添加的屬性值。

          示例:

          <!DOCTYPE html> <html> 	<head> 		<meta charset="utf-8"> 	</head> 	<body> 		<div id="box" style="background-color: black;color: white;border: 2px solid red;">一個div元素</div><br /> 		<button onclick="replaceMessage()"> 修改style屬性的值</a>  			<script type="text/javascript"> 				function replaceMessage() { 					var div = document.getElementById("box");  					div.setAttribute("style","background-color: #FFC0CB;color: black;border: 3px dashed peru;"); 				} 			</script>  	</body> </html>

          javascript怎么修改元素的style屬性

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