<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="" rel="stylesheet">
<style type="text/css">
#box{
width:100px;
height:100px;
background: green;
}
</style>
</head>
<body>
<div id="box" style=''>div</div>
<script type="text/javascript">
/*
一、样式操作
通过style属性添加样式:obj.style.width
带-样式==>驼峰命名:obj.style.backgroundColor = 'red';
*/
var obj = document.getElementById('box');

 

obj.onclick = function(){
obj.style.width = 250+'px';
obj.style.height = 250+'px';
obj.style.backgroundColor = 'red';
obj.style.borderTop = '1px solid green';

}

</script>
</body>
</html>
效果如下                                          
点击前:                                        点击后:
 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title> hello world</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
<style type="text/css">
#box{
width:100px;
height:100px;
background: green;
margin:0 auto
}
</style>
</head>
<body>
<div id="box" style=''>div</div>


<script type="text/javascript">
/*
一、样式操作
obj.style.float = 'left';
*/
var obj = document.getElementById('box');

obj.onclick = function(){
// obj.style.cssText = 'width:250px;height:250px;border-top:1px solid green';
obj.style.float = 'left';
}
</script>
</body>
</html>
 
点击前:              

 

点击后