A table that can add and delete rows and edit the contents of the table _jquery

Source: Internet
Author: User
Tags i18n
Paging file
Copy Code code as follows:

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title></title>
<script type= "Text/javascript" src= "Jquery-1.6.min.js" ></script>
<script type= "Text/javascript" src= "Queryi18n.js" ></script>
<script type= "Text/javascript" >

</script>
<body oncontextmenu= "return false" >



<form id= "I18nform" >
<div id= "I18ntablediv" style= "width:90%;" >
<table id= "i18ntable" border= "1px" width= "90%" >
<tr>
<th width= ' 45% ' height= ' 20px ' >key</th>
<th width= ' 45% ' height= ' 20px ' >value</th>
<th width= ' 5% ' height= ' 20px ' >value</th>
</tr>
</table>
</div>
<div id= "Addtrdiv" style= "width:10%; Float:right; " >
<a href= "#" class= "Easyui-linkbutton" iconcls= "Icon-add" onclick= "ADDTR ()" ><span key= "ss" class= " paltform-i18n > Add Rows </span></a>
</div>
<div class= "Button_area_absolute" >
<table width= "90%" >
<tr>
&LT;TD align=center><a href= "#" class= "Easyui-linkbutton" iconcls= "Icon-ok" onclick= "Savei18ninfo ()" >< Span key= "Save" class= "paltform-i18n" > Save </span></a></td>
</tr>
</table>
</div>
</form>



</body>

JS file
Copy Code code as follows:

Save internationalized Files
function Savei18ninfo () {

var i18ninfo = Geti18ninfo ();
alert (i18ninfo);


}
Get i18n value
function Geti18ninfo () {
var key = "";
var value = "";
var i18ndata = "";
var table = $ ("#i18ntable");
var tbody = Table.children ();
var trs = Tbody.children ();
for (Var i=1;i<trs.length;i++) {
var tds = Trs.eq (i). Children ();
for (Var j=0;j<tds.length;j++) {
if (j==0) {
if (Tds.eq (j). Text () ==null| | Tds.eq (j). Text () = "") {
return null;
}
Key = "key\": \ "" +tds.eq (j). text ();
}
if (j==1) {
if (Tds.eq (j). Text () ==null| | Tds.eq (j). Text () = "") {
return null;
}
Value = "value\": \ "" "+tds.eq (j). text ();
}
}
if (i==trs.length-1) {
I18ndata = "{\" "+key+" \ ", \" "+value+" \ "}";
}else{
I18ndata + = "{\" "+key+" \ ", \" "+value+" \ "},";
}
}
I18ndata = "[" +i18ndata+ "]";
return i18ndata;
}
var clientwidth = document.documentElement.clientWidth;
var clientheight = document.documentElement.clientHeight;
var div_left_width = 200;
var tempwidth = 0;
/**
* Description: Page Adaptive
*/
$ (window). Bind ("Resize", function () {
Resizelayout ();
});
function Resizelayout () {
try{
ClientWidth = Document.documentElement.clientWidth;
var div_left_width = $ ("#left"). Width () +11;
$ ("#cc"). Layout ("resize");
$ (' #userquery '). Panel (' resize ', {width:clientwidth-div_left_width});
$ (' #10100801 '). DataGrid (' resize ', {width:clientwidth-div_left_width});

$ (' #userrange '). ComboBox ({
Width: $ (' #right '). Width () * 0.35
});
}catch (e) {
}
}
function Initresize () {
Automatically adapt to page size
$ (". Layout-button-left"). Bind ("click", Function () {
$ (' #userquery '). Panel (' resize ', {width:clientwidth-28});
$ (' #10100801 '). DataGrid (' resize ', {width:clientwidth-28});
$ (". Layout-button-right"). Bind ("click", Function () {
$ (' #userquery '). Panel (' resize ', {width:tempwidth});
$ (' #10100801 '). DataGrid (' resize ', {width:tempwidth});
});
});
}
function Tdclick (tdobject) {
var td=$ (Tdobject);
Td.attr ("onclick", "");
1, take out the text content in the current TD to Save
var text=td.text ();
2, clear the contents of TD
Td.html (""); can also use Td.empty ();
3, create a text box, which is the element node of input
var input=$ ("<input>");
4, set the value of the text box is saved text content
Input.attr ("value", text);
Input.bind ("Blur", function () {
var inputnode=$ (this);
var inputtext=inputnode.val ();
var tdnode=inputnode.parent ();
Tdnode.html (Inputtext);
Tdnode.click (Tdclick);
Td.attr ("onclick", "Tdclick (This)");
});
Input.keyup (function (event) {
var myevent =event| | window.event;
var Kcode=myevent.keycode;
if (kcode==13) {
var inputnode=$ (this);
var inputtext=inputnode.val ();
var tdnode=inputnode.parent ();
Tdnode.html (Inputtext);
Tdnode.click (Tdclick);
}
});

5, add a text box to the TD
Td.append (input);
var t =input.val ();
Input.val (""). Focus (). val (t);
Input.focus ();

6, Clear Click event
Td.unbind ("click");
}
function Addtr () {
var table = $ ("#i18ntable");
var tr= $ ("<tr><td height= ' 20px ' onclick= ' Tdclick (this) ' >" + "</td><td height= ' 20px ' onclick= ') Tdclick (This) ' > ' + ' </td><td height= ' 20px ' align= ' center ' onclick= ' Deletetr (this) ' ><font size= ' 2 ' color= ' red ' > ' + "delete" + "</font></td></tr>");
Table.append (TR);
}
function Deletetr (tdobject) {
var td=$ (Tdobject);
Td.parents ("tr"). Remove ();
}

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.