行间样式及属性的基本操作

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>通过输入数字改变DIV大小</title>

	<style type="text/css" >
		
		/*#hua2{width: 300px;}*/
	</style>
	<script type="text/javascript" >
		var num=0;
		window.onload=function(){
			hua.onclick=function(){
				num++;
				hua.innerHTML=num;
			};
			//hua2.style.width="300px";
			//cssText可以覆盖原有的css样式(!把之前的css完全覆盖)
			hua2.style.cssText="width:150px;height=150px"
			//getComputedStyle可以获取某元素的演示,行间非行间都可以获取到
			console.log(getComputedStyle(hua2).width);
			//getAttribute可以获取行间的属性,class id style及自定义属性
			console.log(hua2.getAttribute("abc"));
			//设置行间属性:ID class style 等,且可以覆盖原来属性
			hua2.setAttribute("class","hua1");
			//删除行间属性:
			hua2.removeAttribute("id");
			//判断行间属性是否有:
			hua2.hasAttribute("class");			
		};       
	</script>
</head>
<body>
	<xmp><div><span></span></div></xmp>
	<div id='hua' style="width: 100px;height: 100px;background: yellow;">1</div>
	<div id="hua2" abc=10 style="height: 100px;background: pink;"></div>
	
	
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值