Jquery ajax implements double-click content change input box editable

Source: Internet
Author: User
Tags html page


Example.

The code is as follows: Copy code

$ (Function (){
$ ("Tbody> tr: even"). addClass ("dan ");
$ ("Tbody> tr> td"). dblclick (function (){
Var inval = values (this).html ();
Var infd = $ (this). attr ("fd ");
Var inid = $ (this). parents (). attr ("id ");
Certificate (this).html ("");
$ ("# Edit" + infd + inid). focus (). live ("blur", function (){
Var editval = $ (this). val ();
Certificate (this).parents(~td?#.html (editval );
$. Post ("post. php", {id: inid, fd: infd, val: editval });
})
});
});

Html

<Tbody>
<Tr id = "1">
<Td fd = "t"> PHP100 Video 1 </td> <td fd = "d"> 2011 </td> <td fd = "a"> Shanghai </td> </tr>
<Tr id = "2">
<Td fd = "t"> PHP100 Video 2 </td> <td fd = "d"> 2012 </td> <td fd = "a"> Hangzhou </td> </tr>
<Tr id = "3">
<Td fd = "t"> PHP100 video 3 </td> <td fd = "d"> 2011 </td> <td fd = "a"> Jinan </td> </tr>
<Tr id = "4">
<Td fd = "t"> PHP100 video 4 </td> <td fd = "d"> 2011 </td> <td fd = "a"> Beijing </td> </tr>
</Tbody>

Example (complete)

The code is as follows: Copy code
Html page
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> Insert title here </title>
<Script type = "text/javascript" src = "js/jquery. js"> </script>
<Script type = "text/javascript" src = "js/jquery_dblclick.js"> </script>
</Head>
<Body>
   
   
<Table border = "1">
<Thead>
<Tr>
<Td> title </td>
<Td> time </td>
<Td> location </td>
</Tr>
<Thead>
<Tbody>
<Tr id = "1">
<Td fd = "t"> first </td>
<Td fd = "d"> 2012 </td>
<Td fd = "a"> Shanghai </td>
</Tr>
<Tr id = "2">
<Td fd = "t"> second </td>
<Td fd = "d"> 2012 </td>
<Td fd = "a"> Beijing </td>
</Tr>
<Tr id = "3">
<Td fd = "t"> third </td>
<Td fd = "d"> 2012 </td>
<Td fd = "a"> Jinan </td>
</Tr>
</Tbody>
</Table>
</Body>
</Html>

 
Js page
 

The code is as follows: Copy code

$ (Function (){
$ ("Tbody> tr> td"). dblclick (function (){
Var inval = require (this).html (); // Get the html content in td
Var infd = $ (this). attr ("fd"); // obtain the value of the fd attribute of td
Var inid = $ (this). parent (). attr ("id"); // obtain the value of the parent node id attribute of td
       
// Change the html content in td to the input box and assign a value
Certificate (this).html ("<input type = 'text' id = 'edit" + infd + inid + "'value = '" + inval + "'> ");
       
// Obtain the focus in the input box and process the result after the focus is lost.
$ ("# Edit" + infd + inid). focus (). live ("blur", function (){
Var editval = $ (this). val (); // obtain the value in the input box.

Certificate (this0000.parent().html (editval); // assign the obtained value to the html of the parent node of the input box
           
// Submit the post form
$. Post ("jquery_dblclick.php", {id: inid, fd: infd, val: editval}, function (data ){
Alert (data );
})
})
})
})

 
Php page:

The code is as follows: Copy code
<? Php
Header ("Content-Type: text/html; charset = UTF-8 ");
   
$ Conn = mysql_connect ("localhost", "root ","");
Mysql_select_db ("test", $ conn );
Mysql_query ("set names utf8 ");
   
Echo $ val = $ _ POST [val];
   
?>

 

Related Article

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.