Js控制输入字符数限制

From: http://www.phpcake.cn/archives/26/

  1. <script type="text/javascript">
  2. function ismaxlength(obj){ 
  3. var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "" 
  4. if (obj.getAttribute && obj.value.length>mlength) 
  5. obj.value=obj.value.substring(0,mlength) 
  6. } 
  7. </script>
  8.  
  9. <textarea maxlength="10" onkeyup="return ismaxlength(this)"></textarea>
Tags: javascript

相关日志

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

还没有评论。

发表评论

(必填)

(必填)


*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Comment moderation is enabled. Your comment may take some time to appear.