[英]Switch between XML files using JavaScript
我將XML文件用作html頁面的布局,並使用javascript這樣加載它們:
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","default.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
如何在2個或更多布局之間切換?
我正在使用javascript / xml這樣將xml加載到html中:
document.write('<ul id="horizontal-list">');
var x=xmlDoc.getElementsByTagName("APP");
for (i=0;i<x.length;i++)
{
document.write('<li><a class="app_link" href="depiction.php?app=');
document.write(x[i].getElementsByTagName("NAME")[0].childNodes[0].nodeValue);
document.write('&dl=');
document.write(x[i].getElementsByTagName("DOWNLOAD")[0].childNodes[0].nodeValue);
document.write('&install=');
document.write(x[i].getElementsByTagName("INSTALL")[0].childNodes[0].nodeValue);
document.write('">');
document.write('<label class="app_label">');
document.write(x[i].getElementsByTagName("NAME")[0].childNodes[0].nodeValue);
document.write('</label><img class="applicationIcon" src="');
document.write(x[i].getElementsByTagName("ICON")[0].childNodes[0].nodeValue);
document.write('"/></a></li>');
}
document.write('</ul>');
注意:我也在使用CSS樣式表。
使ajax成為如下所示的函數,並使用XML文件的路徑調用該函數:
function getXml($file){
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET",$file,false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
}
而且您也可以發送css文件(在函數中添加第二個參數,並使用jquery append函數來追加樣式表)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.