📄 代码清单6-1.htm
字号:
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#019<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
1'> </span>if (xmlHttp.status == 200) {<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#020<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span>curr_template
= xmlHttp.responseText;<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#021<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span>//alert(curr_template);<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#022<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span>document.getElementById('showdata').innerHTML=curr_template;<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#023<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span>if(curr_xmlDoc){<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#024<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:4'> </span><span
style='mso-spacerun:yes'> </span>fillData(curr_xmlDoc);<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#025<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:3'> </span><span
style='mso-spacerun:yes'> </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#026<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#027<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span>}<span
style='mso-tab-count:1'> </span><o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#028<span
style='mso-spacerun:yes'>
</span>}<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#029<span
style='mso-spacerun:yes'>
</span>//</span><span style='font-size:9.0pt;font-family:宋体;mso-ascii-font-family:
"Times New Roman";mso-hansi-font-family:"Times New Roman"'>改变当前数据显示的模板</span><span
lang=EN-US style='font-size:9.0pt'><o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#030<span
style='mso-spacerun:yes'>
</span>function changeTemplate(template){<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#031<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:1'> </span>if(template){<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#032<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
1'> </span>curr_template_type = template;<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#033<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span>createXMLHttpRequest();<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#034<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span>var
url="/Ajaxstudy/four/getTemplates.jsp?template="+template;<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#035<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#036<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:1'> </span>xmlHttp.open("GET",url,true);<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#037<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
1'> </span>xmlHttp.onreadystatechange = getTemplate;<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#038<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
1'> </span>xmlHttp.send(null);<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#039<span
style='mso-spacerun:yes'>
</span>}<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#040<span
style='mso-spacerun:yes'>
</span>}<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#041<span
style='mso-spacerun:yes'>
</span>//</span><span style='font-size:9.0pt;font-family:宋体;mso-ascii-font-family:
"Times New Roman";mso-hansi-font-family:"Times New Roman"'>向模板中填充数据</span><span
lang=EN-US style='font-size:9.0pt'><o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#042<span
style='mso-spacerun:yes'>
</span>function fillData(xmlDoc){<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#043<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:1'> </span>var dataElems =
xmlDoc.getElementsByTagName('member');<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#044<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:1'> </span>var container =
document.getElementById('list');<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#045<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:1'> </span>if(curr_template_type=='t1'){//</span><span
style='font-size:9.0pt;font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>填充表格模板</span><span lang=EN-US
style='font-size:9.0pt'><span style='mso-spacerun:yes'>
</span><span style='mso-tab-count:2'> </span><o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#046<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:2'> </span>container.innerHTML='<tr><td>ID</td><td></span><span
style='font-size:9.0pt;font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>人名</span><span lang=EN-US
style='font-size:9.0pt'></td></tr>';<span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
2'> </span><o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#047<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:2'> </span>for(i=0;i<dataElems.length;i++){<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#048<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:3'> </span>var
idValue = dataElems[i].childNodes[0].firstChild.nodeValue;<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#049<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:3'> </span>var
nameValue = dataElems[i].childNodes[1].firstChild.nodeValue;<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#050<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
2'> </span>var
newTr = document.createElement('tr');<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#051<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
2'> </span>var
newCell1 = document.createElement('td');<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#052<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
2'> </span>var
newCell2 = document.createElement('td');<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#053<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
2'> </span>newCell1.innerHTML
= idValue;<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#054<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
2'> </span>newCell2.innerHTML
= nameValue;<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#055<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
2'> </span>newTr.appendChild(newCell1);<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#056<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
2'> </span>newTr.appendChild(newCell2);<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#057<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
2'> </span>container.appendChild(newTr);<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#058<span
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -