我是新手,请大家多多指教.有劳高手重写下代码,我的代码如下:
function createXMLHttps(){
var ret=false;
if(window.XMLHttpRequest)
{
ret=new XMLHttpRequest();
if(ret.overrideMimeType){
ret.overrideMimeType('text/xml');
}
}
else if(window.ActiveXObject)
{
try{
ret=new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
ret=new ActiveXObject('Microsoft.XMLHTTP');
}catch(e2){}
}
}
return ret;
}
function ajaxTab(){
var navid=document.getElementById("sidebar").getElementsByTagName("a");//获取id为sidebar的div中a标签的数组
        var navbarURL=navid.getAttribute("href");//在这我想新建一个每个a标签href值的数组,因为下面的xml.open要用到,请问应该怎样写?
navid.onclick=function(){this.style.color="#4baa2b";loadNav();this.blur();return false;}//我想实现当点击#sidebar中的每个链接的时候,链接变色,同时执行loadNav(),在#content里动态加载当前点击链接的链接页面,应该怎样写?for(var i=0;i<navid.length;i++)吗?
function loadNav(){
  var tip=document.getElementById("loadTip");
  var xmlhttp = createXMLHttps();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4){
tip.style.display="inline";
if(xmlhttp.status==200){
document.getElementById("content").innerHTML=xmlhttp.responseText;
tip.style.display="none";
}else{
alert("Communication failure");
}
}
}
  xmlhttp.open("get",navbarURL,true);//我想让这个navbarURL对应到当前点击的链接的href值
xmlhttp.send(null);
}
}
我还有一个想法,就是在执行ajaxTab()的时候调用loadNav(0),预先载入#sidebar里第一个链接的页面,请各位高手指教!谢谢!