您的位置:首页 > Web前端 > CSS

批量设置样式json版

2015-09-08 17:46 603 查看
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="智能社 - zhinengshe.com">
<meta name="copyright" content="智能社 - zhinengshe.com">
<title>智能社 - www.zhinengshe.com</title>
<style>
#div1 { width:200px; height:200px; border:5px solid red; }
</style>
<script>
window.onload=function (){
var oDiv=document.getElementById('div1');

setStyle(oDiv, {
'width' : '500px',
'height': '500px',
'border':'20px solid blue'
});
};

function setStyle(obj, json)
{
for (var i in json)
{
obj.style[i]=json[i];
}
}

</script>
</head>

<body>
<div id="div1"></div>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: