带字数限制提示的输入框效果
2013-02-06 12:37
435 查看
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="jquery.js" type="text/javascript"></script>
</head>
<body>
<textarea name="s1" id="test" rows="5" cols="50" maxlength="10" id="test"></textarea>
<br>共可输入10字符,还剩 <span id="testtest"></span>个字符</font>
</body>
</html>
<script type="text/javascript">
$(function(){
$("#testtest").html(10);
document.getElementById("test").onpropertychange =document.getElementById("test").onkeyup= function(){
var lenE = this.value.length;
var tno = document.getElementById("testtest");
tno.innerHTML = 10 - lenE ;
if (tno.innerHTML < 0) {
var tmp = 0 ;
var cut = this.value.substring(0, 10);
for (var i=0; i<cut.length; i++){
tmp += /[\u4E00-\u9FA5\uF900-\uFA2D]/.test(cut.charAt(i)) ? 2 : 1;
if (tmp > 10) break;
}
this.value = cut.substring(0, 10);
}
}
})
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="jquery.js" type="text/javascript"></script>
</head>
<body>
<textarea name="s1" id="test" rows="5" cols="50" maxlength="10" id="test"></textarea>
<br>共可输入10字符,还剩 <span id="testtest"></span>个字符</font>
</body>
</html>
<script type="text/javascript">
$(function(){
$("#testtest").html(10);
document.getElementById("test").onpropertychange =document.getElementById("test").onkeyup= function(){
var lenE = this.value.length;
var tno = document.getElementById("testtest");
tno.innerHTML = 10 - lenE ;
if (tno.innerHTML < 0) {
var tmp = 0 ;
var cut = this.value.substring(0, 10);
for (var i=0; i<cut.length; i++){
tmp += /[\u4E00-\u9FA5\uF900-\uFA2D]/.test(cut.charAt(i)) ? 2 : 1;
if (tmp > 10) break;
}
this.value = cut.substring(0, 10);
}
}
})
</script>
相关文章推荐
- 验证textarea输入框字数限制,只作提示不作提交限制
- jQuery 类twitter的文本字数限制带提示效果插件
- jQuery 类twitter的文本字数限制带提示效果插件
- 输入框字数限制+动态提示:10个汉字或20个字符的问题
- 效果超酷的textarea的输入字数限制及提示
- 输入框有提示,点击消失,字数限制
- 仿校内textarea输入框字数限制效果
- 输入框输入字数限制
- 如何实现对UITextField ,UITextView等输入框的 字数限制
- jQuery表单获取和失去焦点输入框提示效果的实例代码
- 鼠标放在放在输入框上面提示效果
- 输入框字数提示
- android editText输入文本框限制输入字数和字数提示
- ios中实现对UItextField,UITextView等输入框的字数限制
- inupt textarea提示文字(点击消失,不输入恢复)及限制字数
- 如何实现对UITextField ,UITextView等输入框的 字数限制
- inupt textarea提示文字(点击消失,不输入恢复)及限制字数
- UITextField限制输入字数高亮状态下输入框内真实类容与textFiled(解决中文输入问题)
- (转载)ListView背景问题以及EidtText字数限制和提示
- 仿新浪微博,提示可输入的字数限制 textarea