<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>带多个参数的函数</title>
<style>
#div1{ height:100px; width:100px; background-color:#339;}
</style>
</head>
<body>
<script>
function setStyle(name,value){
var s=document.getElementById(‘div1‘);
s.style[name]=value;
}
</script>
<button onclick="setStyle(‘height‘,‘200px‘)">变高</button>
<button onclick="setStyle(‘width‘,‘200px‘)">变宽</button>
<button onclick="setStyle(‘background-color‘,‘green‘)">变绿</button>
<div id="div1"></div>
</body>
</html>
时间: 2024-11-06 12:16:36