霜天部落 | 关注LAMP高性能、高并发架构的设计与研究

检测剩余可输入字符数js函数

<script language="JavaScript" type="text/JavaScript">
function caculate_length(check_area) //检测剩余可输入字符数

   if (check_area == "title") {
        var text_length = document.getElementById("title").value.length;
        var text_max_length = 25;
        var target_div = document.getElementById("title_length");
        var text_remain = text_max_length – text_length;
        target_div.innerHTML = "<font color=#ff0000>已输入字符:"+text_length+",剩余字符数:"+text_remain+"</font>";
   }else if (check_area == "body") {
       document.getElementById("cbalert").innerHTML ="温馨提示:如果您发帖失败或不小心关闭了当前页面,请不要着急,社区提供了找回功能.请进入发帖页面,再按Ctrl+V,您最后编辑的帖子就恢复了";
      var text_length = document.getElementById("bodycontent").value.length;
      var text_max_length = 4000;
      var target_div = document.getElementById("body_length");
      var text_remain = text_max_length – text_length;
      target_div.innerHTML = "&nbsp;&nbsp;<font color=#ff0000>已输入字符:"+text_length+",剩余字符数:"+text_remain+"</font>";
   }
}
</script>