jquery's Operations on table

Source: Internet
Author: User

<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<script src= "Scripts/jquery-1.8.2.min.js" ></script>
<script src= "Scripts/json2.js" ></script>
<script>

function CreateTable () {
var str = ' Total ': 149, "columns": [{"Field": "EMPLOYEEID", "title": "Employee Number"}, {"Field": "EmployeeName", "title": "Employee Name "}", "Rows": [{"EMPLOYEEID": "001", "EmployeeName": "Xiao Ming"},{"EMPLOYEEID": "002", "EmployeeName": "Small Macro"}]} ';
var data = Json.parse (str);
var rowCount = data.rows.length;
var cellcount = data.columns.length;

var table = $ ("<table border=\" 1\ ">");
Table.appendto ($ ("#createtable"));

var Trheader = $ ("<tr></tr>");
Trheader.appendto (table);
for (var j = 0; J < Cellcount; J + +) {
var td = $ ("<td>" + data.columns[j].title + "</td>");
Td.appendto (Trheader);
}

for (var i = 0; i < RowCount; i++) {
var tr = $ ("<tr></tr>");
Tr.appendto (table);
for (var j = 0; J < Cellcount; J + +) {
var field = Data.columns[j].field;
var val= "";
if (Data.rows[i][field]! = NULL)
{
val = Data.rows[i][field];
}

var td = $ ("<td>" + val + "</td>");
Td.appendto (TR);
}
}
$ ("#createtable"). Append ("</table>");
}

$ (function () {
$ ("A[name=addrow]"). Click (function () {
$ ("#myTable tr:last"). After (' <tr><td>Row4</td></tr> ');
return false;
})
})


$ (document). Ready (function () {
//Hide template tr
$ ("#tb tr"). EQ (2). Hide ();
var i = 0;
$ ("#BtAdd"). Click (f Unction () {
//copy one line
var tr = $ ("#tb tr"). EQ (2). Clone (),
Tr.find ("TD"). Get (0). InnerHTML = ++i;
Tr.show (); tr.appendto ("#tb");
});
$ ("#BtDel"). Click (function () {
$ ("#tb tr:gt (2)"). each (function () {
if () (). Find ("#CK"). Get (0). Checked = = True) {
$ (this). Remove ();
}
});
i = 0;
$ ("#tb tr:gt (2)"). each (function () {
$ (this). FIND ("TD"). Get (0). InnerHTML = ++i;
});
$ ("#CKA"). attr ("checked", false);
});
$ ("#CKA"). Click (function () {
$ ("#tb tr:gt (2)"). each (function () {
$ (this). Find ("#CK"). Get (0). Checked = $ (" #CKA "). Get (0). checked;
});
});
})


$ (function () {
$ ("#btnAdd"). Click (Handleudfproperty);
function Handleudfproperty () {
if ($ ("[tag= ' Udfkey ']"). Size () < 5) {
$ ("#udf_template"). Clone (). Find (": Text"). Val (""). End (). Find ("a"). Click (function () {
$ (this). Parents (' P '). Remove ();
}). End (). AppendTo ($ ("#UDFBlock"));
}
};

Get property value
$ ("#btnGetValue"). On ("click", Function () {
var keys = $ ("[tag= ' Udfkey ']"),
Values = $ ("[tag= ' Udfvalue ']"),
Len = Keys.length,
result = [],
txt = "";

for (var i = 0; i < len; i++) {
TXT + = "{key:" + Keys.eq (i). Val () + ", Value:" + values.eq (i). Val () + "},";
}

$ ("#result"). Text (TXT);
});
})
</script>
<body>

<input type= "button" value= "Add Table" onclick= "CreateTable (5,6)" >
<input type= "button" value= "Add Line" >
<div id= "CreateTable" ></div>
<div id= "CreateRow" ></div>

<table style= "width:100%" id= "myTable" >
<tr><td>Row1</td></tr>
<tr><td>Row2</td></tr>
<tr><td>Row3</td></tr>
</table>
<a href= "#" Name= "AddRow" >add row</a>

<form id= "Form1" >
<div>
<table id= "TB" style= "border:1px solid #000;" >
<tr>
&LT;TD colspan= "style=" Text-align:right ">
<input id= "Btadd" type= "button" value= "Add"/>&nbsp;<input id= "Btdel" type= "button" value= "Delete"/>
</td>
</tr>
<tr>
&LT;TD style= "width:25px;" ></td>
&LT;TD style= "width:25px;" >
<input id= "CKA" name= "CKA" type= "checkbox"/>
</td>
&LT;TD style= "width:20%;" >
Field name
</td>
&LT;TD style= "width:20%;" >
Name
</td>
&LT;TD style= "width:15%;" >
Data type
</td>
&LT;TD style= "width:40px;" >
Primary key
</td>
&LT;TD style= "width:40px;" >
Must fill in
</td>
&LT;TD style= "width:20%;" >
Length
</td>
&LT;TD style= "width:40px;" >
Effective
</td>
&LT;TD style= "width:80px;" >
Sort
</td>
</tr>
<tr>
&LT;TD style= "Text-align:center" ></td>
&LT;TD style= "Text-align:center" >
<input id= "ck" type= "checkbox" name= "ck"/>
</td>
&LT;TD style= "Text-align:center" >
<input id= "Tname" type= "text" name= "Tname"/>
</td>
&LT;TD style= "Text-align:center" >
<input id= "TRM" type= "text" name= "TRM"/>
</td>
&LT;TD style= "Text-align:center" >
<select id= "Stype" name= "Stype" style= "width:100px;" >
<option>1</option>
<option>2</option>
</select>
</td>
&LT;TD style= "Text-align:center" >
<input id= "CKISPR" type= "checkbox" Name= "Ckispr"/>
</td>
&LT;TD style= "Text-align:center" >
<input id= "Ckisnull" type= "checkbox" Name= "Ckisnull"/>
</td>
&LT;TD style= "Text-align:center" >
<input id= "TLen" type= "text" size= "ten" name= "TLen"/>
</td>
&LT;TD style= "Text-align:center" >
<input id= "Ckisuse" type= "checkbox" checked= "Checked" name= "Ckisuse"/>
</td>
&LT;TD style= "Text-align:center" >
<input id= "Txtsortno" type= "text" size= "4" name= "Txtsortno"/>
</td>
</tr>
</table>

<div id= "Result" >

</div>
</div>
</form>


<div id= "Udfblock" >
<p id= "Udf_template" >
<input id= "ck" type= "checkbox" name= "ck"/>
<input type= "text" value= "" tag= "Udfkey" >
<input type= "text" value= "" tag= "Udfvalue" >
<a class= "Udf_delete" style= "Cursor:pointer" >Delete</a>
</p>
</div>
<input type= "button" id= "Btnadd" value= ' Add '/>
<input type= "button" id= "Btngetvalue" value= "Get value"/>
<div id= "Result" >

</div>
</body>

jquery's Operations on table

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.