日期:2014-05-16 浏览次数:20387 次
<!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>
//oTipsNum.innerHTML=140-oTextarea.innerHTML.length; oTipsNum.innerHTML=140-oTextarea.value.length;