欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
  html代码
 
  <pid="includeHtml"></p>
 
  javascript代码
 
  
 
  
 
  
 
  functionclientSideInclude(id,url){
 
  varreq=false;
 
  //Safari,Firefox,及其他非微软浏览器
 
  if(window.XMLHttpRequest){
 
  try{
 
  req=newXMLHttpRequest();
 
  }catch(e){
 
  req=false;
 
  }
 
  }elseif(window.ActiveXObject){
 
  //ForInternetExploreronWindows
 
  try{
 
  req=newActiveXObject("Msxml2.XMLHTTP");
 
  }catch(e){
 
  try{
 
  req=newActiveXObject("Microsoft.XMLHTTP");
 
  }catch(e){
 
  req=false;
 
  }
 
  }
 
  }
 
  varelement=document.getElementById(id);
 
  if(!element){
 
  alert("函数clientSideInclude无法找到id"+id+"。"+
 
  "你的网页中必须有一个含有这个id的p或span标签。");
 
  return;
 
  }
 
  if(req){
 
  //同步请求,等待收到全部内容
 
  req.open('GET',url,false);
 
  req.send(null);
 
  if(req.status==404){
 
  clientSideInclude(id,'error.html')
 
  }else{
 
  element.innerHTML=req.responseText;
 
  }
 
  }else{
 
  element.innerHTML=
 
  "对不起,你的浏览器不支持"+
 
  "XMLHTTPRequest对象。这个网页的显示要求"+
 
  "InternetExplorer5以上版本,"+
 
  "或Firefox或Safari浏览器,也可能会有其他可兼容的浏览器存在。";
 
  }
 
  }
 
  clientSideInclude(includeHtml,"http://XXXXX.html");//页面中的一个p的id为includeHtml





本文转载自中文网

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html5/h55004.shtml