<! 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>
<TD colspan= "style=" Text-align:right ">
<input id= "Btadd" type= "button" value= "Add"/> <input id= "Btdel" type= "button" value= "Delete"/>
</td>
</tr>
<tr>
<TD style= "width:25px;" ></td>
<TD style= "width:25px;" >
<input id= "CKA" name= "CKA" type= "checkbox"/>
</td>
<TD style= "width:20%;" >
Field name
</td>
<TD style= "width:20%;" >
Name
</td>
<TD style= "width:15%;" >
Data type
</td>
<TD style= "width:40px;" >
Primary key
</td>
<TD style= "width:40px;" >
Must fill in
</td>
<TD style= "width:20%;" >
Length
</td>
<TD style= "width:40px;" >
Effective
</td>
<TD style= "width:80px;" >
Sort
</td>
</tr>
<tr>
<TD style= "Text-align:center" ></td>
<TD style= "Text-align:center" >
<input id= "ck" type= "checkbox" name= "ck"/>
</td>
<TD style= "Text-align:center" >
<input id= "Tname" type= "text" name= "Tname"/>
</td>
<TD style= "Text-align:center" >
<input id= "TRM" type= "text" name= "TRM"/>
</td>
<TD style= "Text-align:center" >
<select id= "Stype" name= "Stype" style= "width:100px;" >
<option>1</option>
<option>2</option>
</select>
</td>
<TD style= "Text-align:center" >
<input id= "CKISPR" type= "checkbox" Name= "Ckispr"/>
</td>
<TD style= "Text-align:center" >
<input id= "Ckisnull" type= "checkbox" Name= "Ckisnull"/>
</td>
<TD style= "Text-align:center" >
<input id= "TLen" type= "text" size= "ten" name= "TLen"/>
</td>
<TD style= "Text-align:center" >
<input id= "Ckisuse" type= "checkbox" checked= "Checked" name= "Ckisuse"/>
</td>
<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