<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta charset="utf-8">
<style>
#div1{
width:300px;
height:300px;
border:1px solid red;
background:blue;
}
</style>
<script>
function setstyle(name,value){
var odiv=document.getElementById('div1')
odiv.style['name']=value;
}
</script>
</head>
<body>
<input type="button" value="变色" onclick="setstyle("background","red")" />
<input type="button" value="变宽" onclick="setstyle("width","350px")" />
<div id="div1">
</div>
</body>
</html>
为什么点击变色和变宽按钮:不变宽变色呢?
改两个地方:
function setstyle(name,value){