<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>使用json同时设置多个样式</title>
<style>
#div1{
width: 260px;
height: 260px;
background-color: orange;
}
</style>
<script src="move.js"></script>
<script>
window.onload=function(){
var oBtn=document.getElementById("btn");
var oDiv=document.getElementById("div1");
function setStyle(obj,json){
var attr='';
for (attr in json){
obj.style[attr]=json[attr];
}
}
oBtn.onclick=function(){
setStyle(oDiv,{width:'360px',height:'360px',background:'blue'});
}
}
</script>
</head>
<body>
<div id="div1"></div>
<input type="button" value="点击设置多个值" id="btn">
</body>
</html>
使用json同时设置多个属性值
猜你喜欢
转载自blog.csdn.net/zhangqling/article/details/84574004
今日推荐
周排行