DOM属性的设置和获取

DOM样式操作详解
本文详细介绍了如何使用DOM API修改和获取HTML元素的样式,包括宽度、高度、背景颜色等属性的设置方法,以及如何通过window.getComputedStyle获取元素的所有计算后的样式。
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>DOM样式</title>
	<script type="text/javascript">
			/*
			DOM样式的修改:
				对象.style.属性名=属性值;



				CSS  					DOM

				width					width
				height					height
				background-color        backgroundColor
				font-size				fontSize
				border-color			borderColor
				... 					...
			DOM样式值的获取:
				1.对象.style.属性名	
					只能获取行内样式
				2.
					window.getComputedStyle(对象,null)
					获取指定对象的所有样式


		*/
	</script>
</head>
<body>
	<div id="box"></div>
	<script type="text/javascript">
		var o=document.getElementById("box");
		o.style.width="150px";
		o.style.height="150px";
		o.style.backgroundColor="red";
		o.innerHTML="哈哈";
		o.style.textAlign="center";
		o.style.lineHeight="150px";
		o.style.color="white";
	</script>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值