js中改变不同的div属性值的操作

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#div3{
    width:200px;
    height:200px;
    background:#FF0;
    }
</style>
<script>
function setColor(name,value)
{
    var oDiv=document.getElementById('div3');
    oDiv.style[name]=value;
}
</script>
</head>

<body>

<input type="button" value="变宽"  onclick="setColor('width','500px')"   />
<input type="button" value="变高"  onclick="setColor('height','500px')"/>
<input type="button"  value="变颜色"  onclick="setColor('background','green')"/>
<div id="div3"></div>
</body>
</html>

 

posted @ 2015-07-20 16:02  骏码信息  阅读(1395)  评论(0编辑  收藏  举报