【发布时间】:2016-03-22 10:15:10
【问题描述】:
我的 html 中有 2 个 div,我想通过 onclick 增加大小,但 fontSize 没有改变。
代码:
function changeSize(id, weight, height)
{
with (document)
{
if (getElementById(id).style.width = '240px'){
getElementById(id).style.width = weight + 'px';
getElementById(id).style.height = height + 'px';
getElementById(id).style.fontSize = '30px';
}
else {
getElementById(id).style.width ='240px';
getElementById(id).style.height ='300px';
getElementById(id).style.fontSize = '18px';
}
}
}
.kaesten{
width:240px;
height:300px;
background-color:darkgrey;
background-position:center;
background-repeat:no-repeat;
text-shadow:0px 0px 3px #000;
border: 5px solid #F0F8ff;
vertical-align:top;
text-shadow: 3px 3px 4px #777;
float:left;
margin-left:30px;
}
<div id="box1" class="kaesten" onclick="maxi('box1', 600, 600); return false;">
test1
</div>
<div id="box2" class="kaesten">
test2
</div>
问题:如何更改字体大小?以及如何通过第二次单击将 div 大小再次更改为原始大小?
【问题讨论】:
-
试试
getElementByID(id).style.fontSize = '30px'; -
试试 getElementById(id).style.fontSize = '30' +'px';
-
错误是 ID 而不是 ID
标签: javascript html css font-size maximize