<div class="codetitle"> <span><a style="CURSOR: pointer" data="38770" class="copybut" id="copybut38770" onclick="doCopy('code38770')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code38770"> <br> <br><br> <br> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <br><title></title> <br><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script> <br><script type="text/javascript"> <BR>Array.prototype.filterRepeat = function () { <BR>var res = [], hash = {}; <BR>for (var i = 0, elem; (elem = this[i]) != null; i++) { <BR>if (!hash[elem]) { <BR>res.push(elem); <BR>hash[elem] = true; <BR>} <BR>} <BR>return res; <BR>} <BR>$(function () { <BR>var json = [ <BR>{ "SysName": "数据库", "SysGuid": "1", "CourseName": "SQL", "CourseGuid": "22", "Remarks": "大sb", "firstdate": "2013-1-1", "firstresult": "合格", "secdate": "2013-2-1", "secresult": "合格", "thirddate": "2013-3-1", "thirdresult": "合格" }, <BR>{ "SysName": "数据库", "SysGuid": "1", "CourseName": "MySQL", "CourseGuid": "23", "Remarks": "IQ太低", "firstdate": "2013-1-1", "firstresult": "不合格", "secdate": "2013-2-1", "secresult": "不合格", "thirddate": "2013-3-1", "thirdresult": "合格" }, <BR>{ "SysName": "数据库", "SysGuid": "1", "CourseName": "NoSQL", "CourseGuid": "24", "Remarks": "IQ太低", "firstdate": "2013-1-1", "firstresult": "不合格", "secdate": "2013-2-1", "secresult": "合格", "thirddate": "2013-3-1", "thirdresult": "合格" }, <BR>{ "SysName": "数据库", "SysGuid": "1", "CourseName": "Oracle", "CourseGuid": "25", "Remarks": "IQ太低", "firstdate": "2013-1-1", "firstresult": "不合格", "secdate": "2013-2-1", "secresult": "合格", "thirddate": "2013-3-1", "thirdresult": "合格" }, <BR>{ "SysName": "ASP.NET", "SysGuid": "2", "CourseName": "基础", "CourseGuid": "43", "Remarks": "IQ太低", "firstdate": "2013-1-1", "firstresult": "合格", "secdate": "2013-2-1", "secresult": "不合格", "thirddate": "2013-3-1", "thirdresult": "合格" }, <BR>{ "SysName": "ASP.NET", "SysGuid": "2", "CourseName": "高级", "CourseGuid": "44", "Remarks": "IQ太低", "firstdate": "2013-1-1", "firstresult": "合格", "secdate": "2013-2-1", "secresult": "不合格", "thirddate": "2013-4-1", "thirdresult": "合格" }, <BR>{ "SysName": "JavaScript", "SysGuid": "3", "CourseName": "基础", "CourseGuid": "54", "Remarks": "IQ太低", "firstdate": "2013-1-1", "firstresult": "合格", "secdate": "2013-2-1", "secresult": "合格", "thirddate": "2013-5-1", "thirdresult": "合格" }, <BR>{ "SysName": "JavaScript", "SysGuid": "3", "CourseName": "高级", "CourseGuid": "67", "Remarks": "IQ太低", "firstdate": "2013-1-1", "firstresult": "不合格", "secdate": "2013-2-1", "secresult": "合格", "thirddate": "2013-6-1", "thirdresult": "合格" }, <BR>]; <BR>createTable(json); <br><br>$("#btnsave").click(function () { <BR>$("#ta").text(setDataXML()); <BR>}); <BR>}); <BR>function createTable(json) { <BR>var tb = $("#tb"); <BR>var sys = new Array; <BR>for (var i = 0; i < json.length; i++) { <BR>sys.push(json[i].SysName); <BR>} <BR>//过滤重复 <BR>sys = sys.filterRepeat(); <BR>var tr = null; <BR>for (var j = 0 ; j < sys.length; j++) { <BR>tr += "<tr style='text-align: left' class=gridborder id=p" + j + "><td colspan=8>[-]" + sys[j] + ""; <BR>for (var i = 0; i < json.length; i++) { <BR>if (json[i].SysName == sys[j]) { <BR>tr += "<tr parent=p" + j + " style='text-align: center' pguid='" + json[i].SysGuid + "' cguid='" + json[i].CourseGuid + "'><td>" + json[i].CourseName + "<td>" + setDate(json[i].firstdate) + "<td>" + setSelect(json[i].firstresult) + "<td>" + setDate(json[i].secdate) + "<td>" + setSelect(json[i].secresult) + "<td>" + setDate(json[i].thirddate) + "<td>" + setSelect(json[i].thirdresult) + "<td>" + setInput(json[i].Remarks) + "" <BR>} <BR>} <BR>} <BR>tb.append(tr); <BR>//设置行点击事件 <BR>$("tr.gridborder").css("cursor", "pointer") <BR>.toggle(function () { <BR>var txt = $(this).children().text(); <BR>$(this).children().text(txt.replace("-", "+")); <BR>}, function () { <BR>var txt = $(this).children().text(); <BR>$(this).children().text(txt.replace("+", "-")); <br><br>}).click(function () { <BR>var id = $(this).attr("id"); <BR>$(this).siblings("tr[parent='" + id + "']").toggle(); <BR>}); <BR>//设置选中变色 <BR>$("tr[parent^=p]").toggle(function () { <BR>$(this).attr('bgcolor', '#E3e4e5'); <BR>}, function () { <BR>$(this).attr('bgcolor', '#ffffff'); <BR>}); <BR>} <BR>function setSelect(obj) { <BR>return "<select style='width:96%'><option value ='" + obj + "'>" + obj + "<option value='合格'>合格<option value='不合格'>不合格"; <BR>} <BR>function setDate(obj) { <BR>return "<input style='width:96%' type='text' value='" + obj + "' />"; <BR>} <BR>function setInput(obj) { <BR>return "<input style='width:96%' type='text' value='" + obj + "' />"; <BR>} <BR>function setDataXML() { <BR>var dataxml = $("<DataXML>"); <BR>$("tr[parent^=p]").each(function () { <BR>var item = $("<Course/>"); <BR>var sysguid = $(this).attr("pguid"); <BR>var cguid = $(this).attr("cguid"); <BR>var fdate = $(this).children().children().eq(0).val(); <BR>var fresult = $(this).children().children().eq(1).val(); <BR>var sdate = $(this).children().children().eq(2).val(); <BR>var sresult = $(this).children().children().eq(3).val(); <BR>var tdate = $(this).children().children().eq(4).val(); <BR>var tresult = $(this).children().children().eq(5).val(); <BR>var remark = $(this).children().children().eq(6).val(); <BR>item.attr("SysGuid", sysguid).attr("Remarks", remark).attr("CourseGUID", cguid) <BR>.attr("FirstDate", fdate).attr("FirstResult", fresult) <BR>.attr("SecDate", sdate).attr("SecResult", sresult) <BR>.attr("ThirdDate", tdate).attr("ThirdResult", tresult); <BR>dataxml.append(item); <BR>}); <BR>return dataxml[0].outerHTML; <BR>} <br><br></script> <br> <br> <br><form id="form1" runat="server"> <br><div> <br><br><table id="tb" border="1" style="border-collapse: collapse" width="100%"> <br><tbody> <br><tr style="text-align: center"> <br><td style="width: 100px">课程名称</td> <br><br><td style="width: 120px">初考时间</td> <br><td style="width: 120px">初考成绩</td> <br><td style="width: 120px">次考时间</td> <br><td style="width: 120px">次考成绩</td> <br><td style="width: 120px">清考时间</td> <br><td style="width: 120px">清考成绩</td> <br><td style="width: 250px">备注</td> <br> </tr> <br><br> </tbody> <br> </table> <br> </div> <br><input id="btnsave" type="button" value="保存"> <br><textarea id="ta" cols="100" rows="20"></textarea> <br><br> </form> <br><br> <br> <br> </div>