Use jquery to determine the number of words that can be entered in the input box, And jquery to determine the input box
Effect
All code, paste available
<! 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> untitled document </title>
<Style>
# Comment textarea {height: 100px ;}
# Comment p span {color: red ;}
</Style>
<Script src = "js/jquery-1.7.1.min.js"> </script>
</Head>
<Body>
<Div id = "comment">
<Textarea> </textarea>
<P> You can also enter <span> 300 </span> characters </p>
</Div>
<Script>
$ (Function (){
$ ('# Comment textarea'). keyup (function () {// triggered when the keyboard is up after the input character
Var txtLeng = $ ('# comment textarea'). val (). length; // assign the length of the input character to txtLeng
// Take the input value for determination
If (txtLeng> 300 ){
// When the input length is greater than 300, the span is 0.
$ ('# Comment p span'). text ('0 ');
// Extract the first 300 characters of the input content and assign it to fontsize
Var fontsize = $ ('# comment textarea'). val (). substring (0,300 );
// Display to textarea
$ ('# Comment textarea'). val (fontsize );
} Else {
// If the input length is less than 300, the span value is 300 minus the length.
$ ('# Comment p span'). text (300-txtLeng );
}
});
});
</Script>
</Body>
</Html>
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.