点击按钮 方块变换大小 颜色 隐藏 显示 恢复

第一种

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>改变颜色框</title>

<script>
function mychange(num){
if(num == "1")
{
document.getElementById('div').style.width='400px';
}
if(num == "2")
{
document.getElementById('div').style.height='400px';
}
if(num == "3")
{
document.getElementById('div').style.background = 'blue';
}
if(num == "4")
{
document.getElementById('div').style.height='200px';document.getElementById('div').style.width='200px';document.getElementById('div').style.backgroundColor = 'red';
}
if(num == "5")
{
document.getElementById('div').style.display='none';
}
if(num == "6")
{
document.getElementById ('div').style.display='block';
}
}
</script>
</head>

<body>
<div id="div" style="height:200px; width:200px; background:red"></div>

<p>&nbsp;</p>
<p>
<input type="button" value="变宽" οnclick="mychange(1)" >
<input type="button" value="变高" οnclick="mychange(2)" >
<input type="button" value="变色" οnclick="mychange(3)" >
<input type="button" value="恢复" οnclick="mychange(4)" >
<input type="button" value="隐藏" οnclick="mychange(5)" >
<input type="button" value="显示" οnclick="mychange(6)" >
</p>
</body>
</html>

第二种

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>改变颜色框</title>
<script>
function mychange(p1,p2){
document.getElementById("div").style[p1]=p2;
if(p1 == "huifu")
{
document.getElementById('div').style.height='200px';
document.getElementById('div').style.width='200px';
document.getElementById('div').style.backgroundColor = 'red';
}
}
</script>
</head>

<body>
<div id="div" style="height:200px; width:200px; background:red"></div>

<p>&nbsp;</p>
<p>
<input type="button" value="变宽" οnclick="mychange('width','400px')" >
<input type="button" value="变高" οnclick="mychange('height','400px')" >
<input type="button" value="变色" οnclick="mychange('background','blue')" >
<input type="button" value="恢复" οnclick="mychange('huifu','')" >
<input type="button" value="隐藏" οnclick="mychange('display','none')" >
<input type="button" value="显示" οnclick="mychange('display','block')" >
</p>
</body>
</html>

转载于:https://www.cnblogs.com/moliwanzi/p/3907441.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值