Using jquery imitation as an example of microblogging function

  • 2020-03-30 02:40:39
  • OfStack

The source code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> 
<html xmlns=""> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title> Post box </title> 
<script src="../scripts/jquery-1.3.1.js" type="text/javascript"></script> 
 Function description: when you click the input box, the prompt text will be removed; When the cursor leaves, if nothing is entered, the text of the prompt is restored. If there is input text, the remaining word count is calculated and displayed  
<script type="text/javascript"> 

if ($(this).val()==this.defaultValue) { 
if ($(this).val()=='') { 
var words_num = 140 - $(this).val().length; 
if (words_num < 0) { 
//It's misdirected so there's no return value
// return "<font color='red'>"+words_num+"</font>"; 

$.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'><h6>"+username+":</h6><p class='para'>"+content+"</p></div>"; 
var txtHtml = "<div><h3>"+content+"</h3></div>"; 
$("#resText").html(txtHtml); //Add the returned data to the page

<fieldset style="width:800px; margin-left:300px;"> 
<legend style="font-sixe:16px; font-weight : 600"> Post box </legend> 
<form action="#" id="form1"><!--enctype="multipart/form-data"--> 
 You can also type <span id="num" style="font-size:28px;font-weight:800"><font color="green">140</font></span> A word  
<textarea cols="96" rows="8" id="content"> Just write something down .</textarea> 
<input type="button" id="send" value=" release "/> 
<div> The message you sent was: </div> 
<div id="resText"> 

< img SRC = "border = 0 / / 201431811406 ">  
Problems encountered:

Mainly is the problem of jquery library: using jquery-1.3.1.js this file, can achieve the function, but using jquery-1.7.1.min.js this file, there is no effect! I spent a lot of time to source code to find the problem!!

Related articles: