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: