Source code:
Copy codeThe Code is as follows:
<! 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> release box </title>
<Script src = "../scripts/jquery-1.3.1.js" type = "text/javascript"> </script>
<! --
Function Description: When you click the input box, the text displayed in the prompt will be removed. When the cursor leaves, the text displayed will be restored if no content is entered. If any text is input, the remaining words are calculated and displayed.
-->
<Script type = "text/javascript">
$ (Function (){
$ ("# Content"). focus (function (){
If ($ (this). val () = this. defaultValue ){
$ (This). val ("");
// Alert ($ (this). length-1 );
}
}). Blur (function (){
If ($ (this). val () = ''){
$ (This). val (this. defaultValue );
}
})
$ ("# Content"). keyup (function (){
// Alert ($ (this). val (). length );
Var words_num= 140-$ (this). val (). length;
If (words_num <0 ){
// Misled. In this case, no return value exists.
// $ ("Font"). text (function (words_num ){
// Return "<font color = 'red'>" + words_num + "</font> ";
//});
$ ("Font" ).css ('color', 'red'). text (words_num );
} Else {
$ ("Font"). text (words_num );
// Alert (words_num );
}
})
});
$ (Function (){
$ ("# Send"). click (function (){
$. Post ("post3.php ",{
// Username: $ ("# username"). val (),
Content: $ ("# content"). val ()
}, Function (data, textStatus ){
// Var username = data. username;
Var content = data. content;
// Var txtHtml = "<div class = 'comment'> Var txtHtml = "<div> $ ("# ResText" ).html (txtHtml); // Add the returned data to the page
}, "Json ");
})
});
</Script>
</Head>
<Body>
<Fieldset style = "width: 800px; margin-left: 300px;">
<Legend style = "font-sixe: 16px; font-weight: 600"> release box </legend>
<Form action = "#" id = "form1"> <! -- Enctype = "multipart/form-data" -->
You can also enter <span id = "num" style = "font-size: 28px; font-weight: 800 "> <font color =" green "> 140 </font> </span> characters
<Textarea cols = "96" rows = "8" id = "content"> just write something. </textarea>
<Input type = "button" id = "send" value = "publish"/>
</Form>
</Fieldset>
<Div> the message you sent is: </div>
<Div id = "resText">
</Div>
</Body>
</Html>
:
Problems:
Jquery library is the main problem: the use of jquery-1.3.1.js this file, can achieve the function, but the use of jquery-1.7.1.min.js this file, there is no effect! It took me a lot of time to find the source code !!