//Add a double-click event for each Td
function ReWritable()
{
var tbmian=("tbmain");
//Loop, add a double-click event for each row and column, but the first row (head) and the last row (tfoot) are not added.
for(var i=1;i<-1;i++)
{
for(var j=0;j<[i].;j++)
{
[i].cells[j].ondblclick=TdDoubleClick;
}
}
}
//Define the double-click event of td, add a text box to it, and the user can enter it.
function TdDoubleClick()
{
//First determine whether the text box already exists in the square. If it exists, return and do not add the text box repeatedly. If it does not exist, add.
var tdcag=("tdcag");
var tdid=null;
var txtid=null;
var curtd=;
if(tdcag!=null)//Already exists, return.
{
return;
}
//If it does not exist, add
tdid=;
tdtxt=;
tdtxt=Trim(tdtxt);
var str="<div id='tdcag'><input type='text' onblur='ChangeTdText();' id='txtId' value='"+tdtxt+"'>";
str+="<input type='hidden' id='tdInitValue' value='"+tdtxt+"'>";
str+="</div>";
=str;
//Get the text box to focus.
("txtId").focus();
var ctr=("txtId").createTextRange();
(false);
();
}
//Remove the spaces before and after the string.
function Trim(str)
{
return (/(^\s*)|(\s*$)/g, "");
}
//Define the event when KeyPress is pressed. If it is the ESC key, cancel the change and restore it to the value before the change.
= function EscKeyPress()
{
if(==27)
{
CancelTdChanged();
return;
}
}
//Cancel the change,
function CancelTdChanged()
{
var tdInitValue=("tdInitValue");
var tdtxt=;
var tdid=("tdcag").parentNode;
=Trim(tdtxt);
}
//Confirm the change,
function ChangeTdText()
{
var txtId=("txtId");
if(txtId==null)
{
return;
}
var tdid=("tdcag").parentNode;
=Trim();
return;
}