Php 使用JavaScript在XML文件之间切换
我使用XML文件作为html页面的布局,并使用javascript加载它们 像这样:Php 使用JavaScript在XML文件之间切换,php,javascript,html,xml,xmlhttprequest,Php,Javascript,Html,Xml,Xmlhttprequest,我使用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.resp
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","default.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
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>');
如何在2个或更多布局之间切换
我使用javascript/xml将xml加载到html中,如下所示:
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","default.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
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>');
document.write(“”);
var x=xmlDoc.getElementsByTagName(“应用”);
对于(i=0;i使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文件(向函数添加第二个参数,并使用jqueryappend函数来追加样式表)