关于js中的getElementById

来源:百度知道 编辑:UC知道 时间:2024/05/31 05:29:08
jsp文件中有这样一句话:<font class="font_j01" id="msgCountchange"><%=msgCount%></font>
js文件中使用function messageNum()
{var msgCounttail=document.getElementById("msgCountchange").value;
}
取不到页面的msgCount值,应该怎么改呢?

当然取不到!!!font又不是一个容器。。。
要取的话你应该把这个值放入一个容器
比如说加一句
<input type="hidden" value='<%=msgCount%>' id="msgCountchange"/>

var msgCounttail=<%=msgCount%>;

即可