IE里运行挺正常的,为啥谷歌、火狐里那右上角数字就是不根据内容变呢?拜托各位拉
<!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>
<title>无标题页</title>
</head>
<body>
<div class="message_board">
<label>留言板</label>
<label>您还可以输入<span id="message_tips_num">140</span>字</label>
<form name="message_form" action="" method="post">
<textarea name="message_input" id="message_input" cols="100" rows="4" ></textarea>
</form>
</div>
<script>
var oTipsNum=document.getElementById("message_tips_num");
var oTextarea=document.getElementById("message_input");
var nTextareaFocus=0;
var nNumTimer=null;oTextarea.onfocus=function(){
nNumTimer=setInterval(function(){
oTipsNum.innerHTML=140-oTextarea.innerHTML.length;
if(oTextarea.innerHTML.length>140){
oTipsNum.style.color="red";
oTextarea.style.color="white";
oTextarea.style.backgroundColor="rgb(255,168,168)";
}
else{
oTipsNum.style.color="";
oTextarea.style.color="";
oTextarea.style.backgroundColor="rgb(204,232,207)";
}
},30);
nTextareaFocus=1;
}
oTextarea.onblur=function(){
if(nTextareaFocus==1){
clearInterval(nNumTimer);
nTextareaFocus=0;
nNumTimer=null;
}
}
</script>
</body>
</html>
<!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>
<title>无标题页</title>
</head>
<body>
<div class="message_board">
<label>留言板</label>
<label>您还可以输入<span id="message_tips_num">140</span>字</label>
<form name="message_form" action="" method="post">
<textarea name="message_input" id="message_input" cols="100" rows="4" ></textarea>
</form>
</div>
<script>
var oTipsNum=document.getElementById("message_tips_num");
var oTextarea=document.getElementById("message_input");
var nTextareaFocus=0;
var nNumTimer=null;oTextarea.onfocus=function(){
nNumTimer=setInterval(function(){
oTipsNum.innerHTML=140-oTextarea.innerHTML.length;
if(oTextarea.innerHTML.length>140){
oTipsNum.style.color="red";
oTextarea.style.color="white";
oTextarea.style.backgroundColor="rgb(255,168,168)";
}
else{
oTipsNum.style.color="";
oTextarea.style.color="";
oTextarea.style.backgroundColor="rgb(204,232,207)";
}
},30);
nTextareaFocus=1;
}
oTextarea.onblur=function(){
if(nTextareaFocus==1){
clearInterval(nNumTimer);
nTextareaFocus=0;
nNumTimer=null;
}
}
</script>
</body>
</html>
解决方案 »
- 谁能帮我用javascript实现下面的功能
- JQuery 在循环中设置事件,最后一个覆盖了前面所有的设置,求解决办法.
- fck 编辑器 浏览服务器中的图片 或 文件 排序 在线等!!!
- 如何操作已用showModelessDialog打开的窗口内值?
- 求编程老鸟的js书写规范
- 如何获得滚动条发生了滚动的事件?
- 求救!!!!
- csdn论坛的左边树状菜单栏,点击节点就变白,点击别的就恢复颜色,怎么做到呢?能给出代码吗?
- 关于Javascript特效
- 正则表达式验证电话号码
- 紧急求助 帮忙仿个js效果
- 很简单的问题!怎么把“团结”和“进取”,“友谊”等字放在一个框架下?我的代码出了点小问题!速求各位帮忙!!!!!
oTipsNum.innerHTML=140-oTextarea.value.length;