初学者提问,为什么老是提示 缺少对象啊!

Awang_126 2009-03-18 12:15:51
<html>
<head>
<title>
动态修改页面上的文字的字体
</title>
<script language="javascript">
var newasp_fontsize = 9;
var newasp_lineheight = 18;
//增加字体
addfontsize1 = function()
{
document.getElementById("NewaspContentLabel").style.fontSize = ++newasp_fontsize + "pt"
document.getElementById("NewaspContentLabel").style.lineHeight = ++newasp_lineheight +"pt"
}
//缩小字体
decfontsize2 = function() {
document.getElementById("NewaspContentLabel").style.fontSize = --newasp_fontsize + "pt"
document.getElementById("NewaspContentLabel").style.lineHeight = --newasp_lineheight + "pt"
}
</script>
</head>
<body>
<table width="100%" height="100%" border=1 bordercolor=gray>
<tr>
<td height=24 colspan=2 width="100%" align=right>
<a style="CURSOR: hand; POSITION: relative" title="减小字体" id="addfont"><img onclick="addfontsize1()" src="img/dec.gif" border="0" width="15" height="15"><font color="#FF6600">减小字体</font></a>
<a style="CURSOR: hand; POSITION: relative" title="增大字体" id="decfont"><img src="img/add.gif" border="0" width="15" height="15"><font color="#FF6600">增大字体</font></a>
</td>
</tr>
<tr>
<td width="20%" >
导航栏
</td>
<td idth="80%">

<div id="NewaspContentLabel" style="display:block;padding:0px 10px;LINE-HEIGHT: 18pt;"><FONT id=font_word style="FONT-SIZE: 14px; FONT-FAMILY: 宋体, Verdana, Arial, Helvetica, sans-serif"><P><font face=Verdana>浙江经贸学院周文根一行来中心参观</font></P>
<P>2009年2月27日,浙江经贸学院副院长周文根、教务处处长章剑林、设备处处长梁小碗等一行15人在学校副院长冯浩,设备处处长尤小军,副处长李成和中心副主任张玉才的陪同下进行了参观和交流。</P>
</font></div>


</td>
</tr>
</table>
</body>
</html>
...全文
121 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
十一文 2009-03-18
  • 打赏
  • 举报
回复
 <html>
<head>
<title>
动态修改页面上的文字的字体
</title>
<script language="javascript">
var newasp_fontsize = 9;
var newasp_lineheight = 18;
//增加字体
function addfontsize1()
{
document.getElementById("NewaspContentLabel").style.fontSize = ++newasp_fontsize ;
document.getElementById("NewaspContentLabel").style.lineHeight = ++newasp_lineheight ;
}
//缩小字体
function decfontsize2() {
document.getElementById("NewaspContentLabel").style.fontSize = --newasp_fontsize;
document.getElementById("NewaspContentLabel").style.lineHeight = --newasp_lineheight;
}
</script>
</head>
<body>
<table width="100%" height="100%" border=1 bordercolor=gray>
<tr>
<td height=24 colspan=2 width="100%" align=right>
<a href="#" title="减小字体" id="addfont" onclick="addfontsize1()"> <img src="img/dec.gif" border="0" width="15" height="15"> <font color="#FF6600">减小字体 </font> </a>
<a href="#" title="增大字体" id="decfont" onclick="decfontsize2()"> <img src="img/add.gif" border="0" width="15" height="15"> <font color="#FF6600">增大字体 </font> </a>
</td>
</tr>
<tr>
<td width="20%" >
导航栏
</td>
<td idth="80%">

<div id="NewaspContentLabel" style="display:block;padding:0px 10px;LINE-HEIGHT: 18pt;"> <FONT id=font_word style=" FONT-FAMILY: 宋体, Verdana, Arial, Helvetica, sans-serif"> <P> <font face=Verdana>浙江经贸学院周文根一行来中心参观 </font> </P>
<P>2009年2月27日,浙江经贸学院副院长周文根、教务处处长章剑林、设备处处长梁小碗等一行15人在学校副院长冯浩,设备处处长尤小军,副处长李成和中心副主任张玉才的陪同下进行了参观和交流。 </P>
</font> </div>


</td>
</tr>
</table>
</body>
</html>


测试没得错误了
Awang_126 2009-03-18
  • 打赏
  • 举报
回复
函数调用没有问题,是因为单位有问题,呵呵,谢谢!马上结贴
墨魚丸 2009-03-18
  • 打赏
  • 举报
回复
我试了你的代码,没有报错啊,能正常调整,不过因为你的文字包含在一个<font>中,而你改变的是外层div的字体,所以效果是字体没有改变,但是两个段落间的距离在改变
<FONT id=font_word style="FONT-SIZE: 14px; FONT-FAMILY: 宋体, Verdana, Arial, Helvetica, sans-serif"> <P> <font face=Verdana>浙江经贸学院周文根一行来中心参观 </font> </P>
<P>2009年2月27日,浙江经贸学院P>
</font>


另外,你的“减小字体”,调用的是 addfontsize1(),"增大字体"则用decfontsize2()
Awang_126 2009-03-18
  • 打赏
  • 举报
回复
谢谢!

<script language="javascript" type="text/javascript">
var newasp_fontsize = 9;
var newasp_lineheight = 18;
//增加字体
addfontsize1 = function()
{
document.getElementById("NewaspContentLabel").style.fontSize = ++newasp_fontsize + "px";
document.getElementById("NewaspContentLabel").style.lineHeight = ++newasp_lineheight + "px";
}
//缩小字体
decfontsize2 = function() {
document.getElementById("NewaspContentLabel").style.fontSize = --newasp_fontsize + "px";
document.getElementById("NewaspContentLabel").style.lineHeight = --newasp_lineheight + "px";
}
</script>
这样可以了
Awang_126 2009-03-18
  • 打赏
  • 举报
回复
我想把单位加上去,去掉是可以控制大小了,但是好像单位不正确,提示参数无效
十一文 2009-03-18
  • 打赏
  • 举报
回复
+ "pt"
这里是什么
应该是 ;
Awang_126 2009-03-18
  • 打赏
  • 举报
回复
还是不行啊,
十一文 2009-03-18
  • 打赏
  • 举报
回复
function addfontsize1()
{
document.getElementById("NewaspContentLabel").style.fontSize = ++newasp_fontsize + "pt"
document.getElementById("NewaspContentLabel").style.lineHeight = ++newasp_lineheight +"pt"
}
//缩小字体
function decfontsize2 () {
document.getElementById("NewaspContentLabel").style.fontSize = --newasp_fontsize + "pt"
document.getElementById("NewaspContentLabel").style.lineHeight = --newasp_lineheight + "pt"
}
Awang_126 2009-03-18
  • 打赏
  • 举报
回复
下面的代码:点击缩小字体和增加字体时提示无效对象啊

<html>
<head>
<title>
动态修改页面上的文字的字体
</title>
<script language="javascript">
var newasp_fontsize = 9;
var newasp_lineheight = 18;
//增加字体
addfontsize1 = function()
{
document.getElementById("NewaspContentLabel").style.fontSize = ++newasp_fontsize + "pt"
document.getElementById("NewaspContentLabel").style.lineHeight = ++newasp_lineheight +"pt"
}
//缩小字体
decfontsize2 = function() {
document.getElementById("NewaspContentLabel").style.fontSize = --newasp_fontsize + "pt"
document.getElementById("NewaspContentLabel").style.lineHeight = --newasp_lineheight + "pt"
}
</script>
</head>
<body>
<table width="100%" height="100%" border=1 bordercolor=gray>
<tr>
<td height=24 colspan=2 width="100%" align=right>
<a style="CURSOR: hand; POSITION: relative" onclick="addfontsize1()" title="减小字体" id="addfont"><img src="img/dec.gif" border="0" width="15" height="15"><font color="#FF6600">减小字体</font></a>
<a style="CURSOR: hand; POSITION: relative" onclick="decfontsize2()" title="增大字体" id="decfont"><img src="img/add.gif" border="0" width="15" height="15"><font color="#FF6600">增大字体</font></a>
</td>
</tr>
<tr>
<td width="20%" >
导航栏
</td>
<td idth="80%">

<div id="NewaspContentLabel" style="display:block;padding:0px 10px;LINE-HEIGHT: 18pt;"><FONT id=font_word style="FONT-SIZE: 14px; FONT-FAMILY: 宋体, Verdana, Arial, Helvetica, sans-serif"><P><font face=Verdana>浙江经贸学院周文根一行来中心参观</font></P>
<P>2009年2月27日,浙江经贸学院P>
</font></div>


</td>
</tr>
</table>
</body>
</html>
墨魚丸 2009-03-18
  • 打赏
  • 举报
回复
用 pt 也可以啊,只是要把 " 换成双引号

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧