事件:onclick
属性:width,height,background
用多参函数来简化,注意用onclick调用时的格式是function(){函数名(实参)}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="css1.css" rel="stylesheet" type="text/css"
charset="UTF-8">
</head>
<body>
<input id="btn1" type="button" value="变宽" />
<input id="btn2" type="button" value="变高"/>
<input id="btn3" type="button" value="变色"/>
<div id="div1"></div>
<script src="js1.js"> </script>
</body>
</html>
////////////////////css
#div1{
width:200px;
height:200px;
background:red;
border:1px #ccc solid;
}
/////////////////////js
var oBtn1=document.getElementById("btn1");
var oBtn2=document.getElementById("btn2");
var oBtn3=document.getElementById("btn3");
function getStyle(name,value){
var oDiv=document.getElementById("div1");
oDiv.style[name]=value;
};
oBtn1.onclick=function(){
getStyle(‘width‘,‘300px‘);};
oBtn2.onclick=function(){
getStyle(‘height‘,‘300px‘);};
oBtn3.onclick=function(){
getStyle(‘background‘,‘green‘);};