用js修改CSS属性

用js修改CSS属性 - 截拳道 -  The future is in my
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<style type="text/css">
.div_c{
   color:#FF0000;
   font-style:italic;
   font-size:10px;
   }
</style>
<script type="text/javascript">
function js_change(){//添加样式
document.getElementById('d1').className='div_c';
}
function setSize()//设置大小
{
    document.getElementById( "d1" ).style.fontSize = "30px";
}
function setColor()//设置颜色
{
    document.getElementById( "d1" ).style.color = "black";
}
function setbgColor()//设置背景色
{
    document.getElementById( "d1" ).style.backgroundColor = "blue";
}
function setBd()//设置边框
{
    document.getElementById( "d1" ).style.border = "3px solid #FA8072";
}
function setImg(){//设置图片
    document.body.style.backgroundImage = "url(http://www.google.cn/intl/zh-CN/images/logo_cn.gif)";
}
function setWidth(){//设置宽度
  document.getElementById( "d1" ).style.width = "40%";
}
function setCenter(){//居中显示
  document.getElementById( "d1" ).style.textAlign = "center";
}
</script>
</head>
<body>
 <div class="" id="d1">
  变!变!变!
 </div>
 <button οnclick="js_change()">变</button>
 <button οnclick="setSize()">变大</button>
 <button οnclick="setbgColor()">变景</button>
 <button οnclick="setColor()">变色</button>
 <button οnclick="setBd()">变框</button>
 <button οnclick="setImg()" >变图</button>
 <button οnclick="setWidth()" >变窄</button>
  <button οnclick="setCenter()" >变后</button>
</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值