Use Jquery to change the clicked text to a text box and change it to jquery.

Source: Internet
Author: User
Tags html header
Use Jquery to change text to text box. You can modify the text box as follows, we hope it will be helpful for you to use Jquery to change the text to the text box. You can modify the text in the text box.

1. Click text to change to text box
2. the text box automatically selects all text
3. Modify the text box content
4. Click a text box other than the text box to change it to the modified text box again.
5. Synchronously update SQL database content

Html code

The Code is as follows:























ID Name Operation
1 Haha Delete
2 Haha Delete
3 Haha Delete


Create an edit. js file with the following code:

The Code is as follows:


$ (Function (){
// Obtain the elements whose class is caname
$ (". Caname"). click (function (){
Var td = $ (this );
Var txt = td. text ();
Var input = $ ("");
Td.html (input );
Input. click (function () {return false ;});
// Obtain the focus
Input. trigger ("focus ");
// If the text box loses focus, the submitted content is changed to text
Input. blur (function (){
Var newtxt = $ (this). val ();
// Determine whether the text has been modified
If (newtxt! = Txt ){
Td.html (newtxt );
/*
* This section does not need to use databases.
Var caid = $. trim (td. prev (). text ());
// Ajax changes the database asynchronously. Adding the date parameter solves the cache problem.
Var url = "../common/Handler2.ashx? Caname = "+ newtxt +" & caid = "+ caid +" & date = "+ new Date ();
// Use the get () method to open a general processing program. data accepts the returned parameters (the method context for returning parameters in a general processing program. response. write ("parameters to be returned ");)
// Modify the database in the general processing program.
$. Get (url, function (data ){
If (data = "1 ")
{
Alert ("This category already exists! ");
Td.html (txt );
Return;
}
Alert (data );
Td.html (newtxt );
});
*/
}
Else
{
Td.html (newtxt );
}
});
});
});


Reference the jq class library file and self-written edit. js file in the Html header. Pay attention to the sequence.

The Code is as follows:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.