Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> </title>
<Script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"> </script>
<Script type = "text/javascript">
Array. prototype. filterRepeat = function (){
Var res = [], hash = {};
For (var I = 0, elem; (elem = this [I])! = Null; I ++ ){
If (! Hash [elem]) {
Res. push (elem );
Hash [elem] = true;
}
}
Return res;
}
$ (Function (){
Var json = [
{"SysName": "Database", "SysGuid": "1", "CourseName": "SQL", "CourseGuid": "22", "Remarks ": "Large sb", "firstdate": "2013-1-1 1-1", "firstresult": "qualified", "secdate": "2013-2-1", "secresult": "qualified ", "thirddate": "2013-3-1", "thirdresult": "qualified "},
{"SysName": "Database", "SysGuid": "1", "CourseName": "MySQL", "CourseGuid": "23", "Remarks ": "IQ is too low", "firstdate": "2013-1-1 1-1", "firstresult": "unqualified", "secdate": "2013-2-1", "secresult": "unqualified ", "thirddate": "2013-3-1", "thirdresult": "qualified "},
{"SysName": "Database", "SysGuid": "1", "CourseName": "NoSQL", "CourseGuid": "24", "Remarks ": "IQ is too low", "firstdate": "2013-1-1 1-1", "firstresult": "unqualified", "secdate": "2013-2-1", "secresult": "qualified ", "thirddate": "2013-3-1", "thirdresult": "qualified "},
{"SysName": "Database", "SysGuid": "1", "CourseName": "Oracle", "CourseGuid": "25", "Remarks ": "IQ is too low", "firstdate": "2013-1-1 1-1", "firstresult": "unqualified", "secdate": "2013-2-1", "secresult": "qualified ", "thirddate": "2013-3-1", "thirdresult": "qualified "},
{"SysName": "ASP. NET "," SysGuid ":" 2 "," CourseName ":" Basic "," CourseGuid ":" 43 "," Remarks ":" IQ is too low ", "firstdate": "2013-1-1 1-1", "firstresult": "qualified", "secdate": "2013-2-1", "secresult": "unqualified", "thirddate ": "2013-3-1", "thirdresult": "qualified "},
{"SysName": "ASP. NET "," SysGuid ":" 2 "," CourseName ":" advanced "," CourseGuid ":" 44 "," Remarks ":" IQ is too low ", "firstdate": "2013-1-1 1-1", "firstresult": "qualified", "secdate": "2013-2-1", "secresult": "unqualified", "thirddate ": "2013-4-1", "thirdresult": "qualified "},
{"SysName": "JavaScript", "SysGuid": "3", "CourseName": "Basic", "CourseGuid": "54", "Remarks ": "IQ is too low", "firstdate": "2013-1-1 1-1", "firstresult": "qualified", "secdate": "2013-2-1", "secresult": "qualified ", "thirddate": "2013-5-1", "thirdresult": "qualified "},
{"SysName": "JavaScript", "SysGuid": "3", "CourseName": "advanced", "CourseGuid": "67", "Remarks ": "IQ is too low", "firstdate": "2013-1-1 1-1", "firstresult": "unqualified", "secdate": "2013-2-1", "secresult": "qualified ", "thirddate": "2013-6-1", "thirdresult": "qualified "},
];
CreateTable (json );
$ ("# Btnsave"). click (function (){
$ ("# Ta"). text (setDataXML ());
});
});
Function createTable (json ){
Var tb = $ ("# tb ");
Var sys = new Array;
For (var I = 0; I <json. length; I ++ ){
Sys. push (json [I]. SysName );
}
// Filter duplicate
Sys = sys. filterRepeat ();
Var tr = null;
For (var j = 0; j <sys. length; j ++ ){
Tr + = "<tr style = 'text-align: left 'class = gridborder id = p "+ j +"> <td colspan = 8> [-] "+ sys [j] +" </td> </tr>";
For (var I = 0; I <json. length; I ++ ){
If (json [I]. SysName = sys [j]) {
Tr + = "<tr parent = p" + j + "style = 'text-align: center 'pguid = '" + json [I]. sysGuid + "'cguid = '" + json [I]. courseGuid + "'> <td>" + json [I]. courseName + "</td> <td>" + setDate (json [I]. firstdate) + "</td> <td>" + setSelect (json [I]. firstresult) + "</td> <td>" + setDate (json [I]. secdate) + "</td> <td>" + setSelect (json [I]. secresult) + "</td> <td>" + setDate (json [I]. thirddate) + "</td> <td>" + setSelect (json [I]. thirdresult) + "</td> <td>" + setInput (json [I]. remarks) + "</td> </tr>"
}
}
}
Tb. append (tr );
// Set the row Click Event
$ ("Tr. gridborder" ).css ("cursor", "pointer ")
. Toggle (function (){
Var txt = $ (this). children (). text ();
$ (This). children (). text (txt. replace ("-", "+ "));
}, Function (){
Var txt = $ (this). children (). text ();
$ (This). children (). text (txt. replace ("+ ","-"));
}). Click (function (){
Var id = $ (this). attr ("id ");
$ (This). siblings ("tr [parent = '" + id + "']"). toggle ();
});
// Set the selected color.
$ ("Tr [parent ^ = p]"). toggle (function (){
$ (This). attr ('bgcolor', '# e3e4e5 ');
}, Function (){
$ (This). attr ('bgcolor', '# ffff ');
});
}
Function setSelect (obj ){
Return "<select style = 'width: 96% '> <option value =' "+ obj +" '> "+ obj +" </option> <option value = 'qualified'> qualified </option> <option value = 'unqualified '> unqualified </option> </select> ";
}
Function setDate (obj ){
Return "<input style = 'width: 96% 'type = 'text' value ='" + obj + "'/> ";
}
Function setInput (obj ){
Return "<input style = 'width: 96% 'type = 'text' value ='" + obj + "'/> ";
}
Function setDataXML (){
Var dataxml =$ ("<DataXML> </DataXML> ");
$ ("Tr [parent ^ = p]"). each (function (){
Var item = $ ("<Course/> ");
Var sysguid = $ (this). attr ("pguid ");
Var cguid = $ (this). attr ("cguid ");
Var fdate = $ (this). children (). children (). eq (0). val ();
Var fresult = $ (this). children (). children (). eq (1). val ();
Var sdate = $ (this). children (). children (). eq (2). val ();
Var sresult = $ (this). children (). children (). eq (3). val ();
Var tdate = $ (this). children (). children (). eq (4). val ();
Var tresult = $ (this). children (). children (). eq (5). val ();
Var remark = $ (this). children (). children (). eq (6). val ();
Item. attr ("SysGuid", sysguid). attr ("Remarks", remark). attr ("CourseGUID", cguid)
. Attr ("FirstDate", fdate). attr ("FirstResult", fresult)
. Attr ("SecDate", sdate). attr ("SecResult", sresult)
. Attr ("ThirdDate", tdate). attr ("ThirdResult", tresult );
Dataxml. append (item );
});
Return dataxml [0]. outerHTML;
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Table id = "tb" border = "1" style = "border-collapse: collapse" width = "100%">
<Tbody>
<Tr style = "text-align: center">
<Td style = "width: 100px"> Course name </td>
<Td style = "width: 120px"> preliminary test time </td>
<Td style = "width: 120px"> preliminary score </td>
<Td style = "width: 120px"> exam time </td>
<Td style = "width: 120px"> secondary exam score </td>
<Td style = "width: 120px"> test time </td>
<Td style = "width: 120px"> clear test score </td>
<Td style = "width: 250px"> remarks </td>
</Tr>
</Tbody>
</Table>
</Div>
<Input id = "btnsave" type = "button" value = "save"/>
<Textarea id = "ta" cols = "100" rows = "20"> </textarea>
</Form>
</Body>
</Html>