| The code is as follows |
Copy Code |
| <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/> </title> for <title> Test <script language= "javascript" src= "Demo2/jquery-1.3.2.min.js" ></script>
<body> <table width= "66%" border= "0" cellspacing= "0" cellpadding= "0" > <tr> <TD height= "align=" "Center" ><strong> username </strong></td> <TD align= "Center" ><strong> Email address </strong></td> </tr> <tr> <TD class= "UNM" uid=1 id= "unm1" filed= "UNM" > User a</td> <TD class= "Email" uid=1 id= "email1" filed= "email" >usera@domain.con</td> </tr> <tr> <TD class= "UNM" uid=2 id= "unm2" filed= "UNM" > User b</td> <TD class= "Email" uid=2 id= "email2" filed= "email" >userb@domain.com</td> </tr> </table> </body> |
There are 2 custom properties in the TD tag in the HTML code, uid,filed, the first UID is used to represent the ID field in the corresponding table in the database, filed is used to indicate which of the data in the TD represents the field in the table.
Here is the JS code:
JavaScript code
| The code is as follows |
Copy Code |
| <script language= "JavaScript" > $ (). Ready (function () { $ (". Unm,.email"). DblClick (function () { id=$ (This). attr ("UID"); value=$ (This). text (); f=$ (This). attr ("field"); text_id=$ (This). attr ("id"); if (value) { $ (this). HTML ("<input type= ' text ' id=" +id+ "name=" +f+ "value=" +value+ ">"); $ (". UNM > Input,.email>input"). focus (). blur (function () {
$.ajax ({ Type: "POST", URL: "save.php", Data: "id=" +id+ "&type=" +f+ "&value=" +$ ("#" +id). Val (), Success:function (msg) {$ ("#" +text_id). Text (msg); }); })
}
})
}) </script> |
save.php
PHP code
| code is as follows |
copy code |
<?php //Save to Database if ($_post["type"]== "email") { //mysql_query ("Update sometable set email= ' {$_post[" value "]} ' where id={$_post[" id "}"); } if ($_post["type"]== "UNM") { //mysql_query (" Update sometable set unm= ' {$_post[' value '} ' where id={$_post[' id '} '); } E Cho $_post["value"]; ?> |
The
principle is simple: double-click the contents of the ID into input, and then save the same as the ID form post past, and then use PHP to enter the save.