jquery implements editable table example explanations (2) _jquery

Source: Internet
Author: User

The results we will eventually achieve are as follows:

When you click on the Learning Number column, you can edit it:

When you click ESC, the action is canceled, and when you click Enter, the modification takes effect (no interaction with the background)
The page code is as follows (asp.net):

<%@ Page language= "C #" autoeventwireup= "true" codefile= "EditTable.aspx.cs" inherits= "edittable"%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

CSS (EIDTTABLE.CSS)

Table 
{ 
 border:1px solid black; 
 Border-collapse:collapse; 
 width:500px; 
 } 
Table th 
{ 
 border:1px solid black; 
 width:50%; 
 } 
Table TD 
{ 
 border:1px solid black; 
 width:50px; 
 } 
tbody th 
{ 
 background-color: #A3BAE9 
 }

JS (eidttable.js):

<reference path= "Jquery-1.9.1.min.js"/>//$ (document). Ready (function () {//alert (' Test '); 
 
//}); 
 Simple wording $ (function () {$ ("tr:odd"). CSS ("Background-color", "#ECE9D8"); 
 
 var OBJTD = $ (". Edittd"); 
 Objtd.click (function () {var text = $ (this). html (); 
 
 var objthistd = $ (this); 
 Solve the problem if you click between the text box and the TD in the middle of the question if (Objthistd.children ("input"). Length > 0) {return false; 
 
 var Inputtext = $ ("<input value= ' test ' type= ' text '/>"); Inputtext.width (Objtd.width ()). CSS ("Font-size", "16px"). CSS ("Background-color", Objtd.css ("Background-color")). 
 
 CSS ("border-width", "0"). val (text); 
 Objthistd.html (""); 
 
 Inputtext.appendto (OBJTHISTD); 
 
 Inputtext.trigger ("Focus"). Trigger ("select"); 
 Inputtext.click (function () {return false; 
 
 }); 
 The KeyDown event used here, I tried to use the KeyUp event could not mask the browser's return page submission event Inputtext.keydown (function (event) {//alert (Event.keycode); 
 var keycode = Event.which; 
 if (keycode =) {objthistd.html ($ (this). Val ()); Return False 
 } if (keycode = =) {objthistd.html (text); 
 } 
 }); 
 
 
});  });

The above is the implementation of editable form all the code, I hope you can carefully study, apply to their own website.

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.