通过js来修改div的style(background,border,。。。。。。。)

时间:2022-10-23 09:07:20
 <!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
#div{width:100px;height:200px;border:2px solid red;background:blue;}
</style>
<script>
window.onload=function(){
var style1=document.getElementById('style1');
var shu=document.getElementById('shu');
var button1=document.getElementById('button1'); button1.onclick=function(){
div.style[style1.value]=shu.value;
};
};
</script>
</head>
<body>
请输入样式:<input id="style1" type="text" value=""/><br/>
请输入数据:<input id="shu" type="text" value=""/>
<input id="button1" type="button" value="button"/>
<div id="div"></div> </body> </html>