$ (Function (){ $ ("Td"). click (function (event ){ // If input already exists in td, you do not need to respond to the Click Event If ($ (this). children ("input"). length> 0) Return false; Var tdObj = $ (this ); Var preText = tdObj.html (); // Obtain the current text content Var inputObj = $ ("<input type = 'text'/> "); // Create a text box element TdObj.html (""); // clear all elements in td InputObj . Width (tdObj. width ()) // Set the text box to the same width as td . Height (tdObj. height ()) . Css ({border: "0px", fontSize: "17px", font: ""}) . Val (preText) . AppendTo (tdObj) // Insert the text box to the end of the tdObj subnode. . Trigger ("focus ") // Trigger an event using the trigger Method . Trigger ("select "); InputObj. keyup (function (event ){ If (13 = event. which) // Press ENTER { Var text = $ (this). val (); TdObj.html (text ); } Else if (27 = event. which) // ESC key { TdObj.html (preText ); } }); // After the click event is edited, the click event is not processed. InputObj. click (function (){ Return false; }); }); }); |