龙空技术网

Javascript取到非行间样式实现点击按钮改变样式

编程鲍老师 133

前言:

而今咱们对“js获取点击按钮的id”大约比较重视,我们都想要知道一些“js获取点击按钮的id”的相关资讯。那么小编也在网摘上汇集了一些有关“js获取点击按钮的id””的相关资讯,希望同学们能喜欢,咱们快快来学习一下吧!

<!DOCTYPE html><html>	<head>		<meta charset="utf-8">		<title></title>		<style>			#box{				width: 300px;				height: 300px;				border: 2px solid black;				background-color: yellow;			}		</style>		<script>			var w;			var h;			// currentStyle IE			var i=1;			var j=1;			var c=0;			function cool(name,value){				var odiv=document.getElementById('box');				var obj_w=getComputedStyle(odiv,false).width;				var obj_h=getComputedStyle(odiv,false).height;				var obj_c=getComputedStyle(odiv,false).backgroundColor;				if(name=='width'){					 w=parseInt(obj_w)+parseInt(value)*i+'px';					 i+=1;					odiv.style[name]=w;				}				else if(name=='height'){					h=parseInt(obj_h)+parseInt(value)*j+'px';					j+=1;					odiv.style[name]=h;				}else if(name=='backgroundColor')				{					if(c==value.length)						c=0;					odiv.style[name]=value[c]					c+=1;  				}			}		</script>	</head>	<body>		<input  type="button" value="变宽" onclick="cool('width','100');"/>		<input  type="button" value="变高" onclick="cool('height','100');"/>		<input  type="button" value="变红" onclick="cool('backgroundColor',['red','yellow','pink','purple']);"/>		<br>		<div id="box"></div>	</body></html>

标签: #js获取点击按钮的id