现在的位置: 首页 > 综合 > 正文

textaera maxlength

2012年03月09日 ⁄ 综合 ⁄ 共 1490字 ⁄ 字号 评论关闭

<html>
<script type="text/javascript" language="javascript">
    function ismaxlength(obj)
    { 
 alert(obj.value.length);
        var mlength=obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : "";
     if (obj.getAttribute && obj.value.length>mlength) 
     { 
         obj.value=obj.value.substring(0,mlength) 
     }
    } 
     
     
    function imposeMaxLength(obj)
    { 

        var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
        if(obj.value.length >= mlength)
  {
   obj.value=obj.value.substring(0,mlength) 
  }
  
  if(obj.value.length >512)
  {
   document.getElementById("show1024").value = obj.value.length;
  }
  else
  {
   document.getElementById("show512").value = obj.value.length;
  }

    }
</script>
<div>
<span style="width:480px;float:left;" ><input type="text" id="show512" value="" /><input type="button" value="Clear" onclick="javascript:document.getElementById('show512').value=''" /></span>
<span style="width:480px;float:right;"><input type="text" id="show1024" value="" />
<input type="button" value="Clear" onclick="javascript:document.getElementById('show1024').value=''" />
</span>
</div>
<div>
<span style="float:left;">
<textarea maxlength="512" title="512" style="width:480px; height:800px;" onblur="javascript:imposeMaxLength(this);" onkeypress="javascript:ismaxlength(this);"> fs </textarea>
</span>
<span style="float:right;">
<textarea maxlength="1024" title="1024" style="width:480px; height:800px;" onblur="javascript:imposeMaxLength(this);" onkeypress="javascript:ismaxlength(this);"> fs </textarea>
</span>
</div>
</html>

抱歉!评论已关闭.