<textarea name=
"content"
id=
"content"
style=
"width:345px;height:120px;"
></textarea><div id=
"contentwordage"
></div>
<script type=
"text/javascript"
>
$(document).ready(
function
(){
var
limitNum = 500;
var
pattern =
'还可以输入'
+ limitNum +
'字符'
;
$(
'#contentwordage'
).html(pattern);
$(
'#content'
).keyup(
function
(){
var
remain = $(
this
).val().length;
if
(remain > 500){
pattern =
"字数超过限制!"
;
}
else
{
var
result = limitNum - remain;
pattern =
'还可以输入'
+ result +
'字符'
;
}
$(
'#contentwordage'
).html(pattern);
}
);
});
</script>
|
转载于:https://www.cnblogs.com/sky-yu/p/6217855.html