js-dom实现字体大小、背景颜色的转换

本文介绍了一种通过JavaScript实现网页背景颜色及字体大小动态调整的方法。用户可通过点击不同颜色块来改变页面背景颜色,也可以选择大、中、小三种字体大小。这种方式增强了网页的互动性和个性化体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!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>
<style>
 .k1{
 height:10px;
 width:10px;
 border:1px #00F solid;
 margin:2px;
 float:right;
 cursor:pointer;
 
  }
span{
 cursor:pointer;
 } 

</style>


<script language="javascript" type="text/javascript">
 /*
 思路:
   1、先制定出一些小的颜色区块
 */
 function changeColor(color){
 
  //设置背景颜色
 document.bgColor=color;
 
  }
 
 function changeSize(size){
 
  //获取div对象
document.getElementById("content").style.fontSize=size+"px";
  
   }

 

</script>

</head>
<body>

<div class="k1" style="background-color:#FFC"
onclick="changeColor('#ffffcc')"></div>
<div class="k1" style="background-color:#FCC"
onclick="changeColor('#ffcccc')"></div>
<div class="k1" style="background-color:#F9C"
onclick="changeColor('#ff99cc')"></div>


<span onclick="changeSize(26)">大</span>
<span onclick="changeSize(16)">中</span>
<span onclick="changeSize(14)">小</span>
<hr style="clear:both">

<div id="content">
关于四级的通过宝典<br>
三短一长,选短的,三段一长。选长的;长短布衣要选B,层次不齐要选D;
沂蒙为主,以抄为主,蒙抄结合,四级必过!

</div>

 


</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值