html中当单击文档中的按钮时,可以将字体变大或者变小,照着书上编的,可是为什么按按钮实现不了?
<html><head><metahttp-equiv="content-type"content="text/html;charset=utf-8"/><title>s...
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>setAttribute</title>
<style type="text/css">
.control{
text-align:right;
}
.lbtn{
font-size:18px;
}
.sbtn{
font-size:10px;
}
.nomal{
font-size:12px;
}
.larger{
font-size:18px;
}
.smaller{
font-size:10px;
}
</style>
<script language="javascript">
function EnlargeFontsize()
{
var content=document.getElementById("content");
var css=content.getAttribute("class");
if(css=="normal")
{
content.setAttribute("class","larger");
}
if(css=="smaller")
{
content.setAttribute("class","normal");
}
}
function ReduceFontsize()
{
var content=document.getElementById("content");
var css=content.getAttribute("class");
if(css=="normal")
{
content.setAttribute("class","smaller");
}
if(css=="larger")
{
content.setAttribute("class","normal");
}
}
</script>
</head>
<body>
<div class="control">
<span class="sbtn"><a href="#" onClick="ReduceFontsize();" title="缩小字体">T</a></span>|
<span class="lbtn"><a href="#" onClick="EnlargeFontsize();" title="放大字体">T</a></span>
</div>
<div class="nomal" id="content">七年,情感版编辑李春天每天都收到大量怨妇来稿。闪婚、离婚、再婚,战男人,斗女人,养儿女,每一封信都在向李春天讲述情感血泪史,每一个无不是被男人骗吃骗喝骗炮打,简直惨不忍睹,歇斯底里。</div>
</body>
</html> 展开
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>setAttribute</title>
<style type="text/css">
.control{
text-align:right;
}
.lbtn{
font-size:18px;
}
.sbtn{
font-size:10px;
}
.nomal{
font-size:12px;
}
.larger{
font-size:18px;
}
.smaller{
font-size:10px;
}
</style>
<script language="javascript">
function EnlargeFontsize()
{
var content=document.getElementById("content");
var css=content.getAttribute("class");
if(css=="normal")
{
content.setAttribute("class","larger");
}
if(css=="smaller")
{
content.setAttribute("class","normal");
}
}
function ReduceFontsize()
{
var content=document.getElementById("content");
var css=content.getAttribute("class");
if(css=="normal")
{
content.setAttribute("class","smaller");
}
if(css=="larger")
{
content.setAttribute("class","normal");
}
}
</script>
</head>
<body>
<div class="control">
<span class="sbtn"><a href="#" onClick="ReduceFontsize();" title="缩小字体">T</a></span>|
<span class="lbtn"><a href="#" onClick="EnlargeFontsize();" title="放大字体">T</a></span>
</div>
<div class="nomal" id="content">七年,情感版编辑李春天每天都收到大量怨妇来稿。闪婚、离婚、再婚,战男人,斗女人,养儿女,每一封信都在向李春天讲述情感血泪史,每一个无不是被男人骗吃骗喝骗炮打,简直惨不忍睹,歇斯底里。</div>
</body>
</html> 展开
1个回答
推荐于2018-04-23
展开全部
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>setAttribute</title>
<style type="text/css">
.control {
text-align: right;
}
.lbtn {
font-size: 18px;
}
.sbtn {
font-size: 10px;
}
.normal {
font-size: 15px;
}
.larger {
font-size: 20px;
}
.smaller {
font-size: 10px;
}
</style>
<script>
function toggleFontSize(flag) {
var content = document.getElementById("content");
if(flag == -1){
content.className = "smaller";
}else if(flag == 1){
content.className = "larger";
}else if(flag == 0){
content.className = "normal";
}
}
</script>
</head>
<body>
<div class="control"> <span class="sbtn">
<a href="###" onClick="toggleFontSize(-1);" title="缩小字体">T</a></span>
|
<span class="lbtn">
<a href="###" onClick="toggleFontSize(1);" title="放大字体">T</a></span>
|
<span calss="lbtn">
<a href="###" onclick="toggleFontSize(0)" title="重置字体">T</a>
</span>
</div>
<div class="normal" id="content">
七年,情感版编辑李春天每天都收到大量怨妇来稿。闪婚、离婚、再婚,战男人,斗女人,养儿女,每一封信都在向李春天讲述情感血泪史,每一个无不是被男人骗吃骗喝骗炮打,简直惨不忍睹,歇斯底里。
</div>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询