国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

具有郵編區號查詢功能的js+xml版

2019-11-18 12:48:57
字體:
來源:轉載
供稿:網友

  這幾天制作一個系統的郵編區號查詢功能,突發奇想制作了這個js+xml版的,因為xml數據量較大(2000多條記錄),所以若是網速較慢的話,會有畫面停頓的現象,我曾打算預加載xml數據,可惜沒能實現(光找到了預加載圖片的方法,你要知道預加載xml的方法可以告訴我,謝謝)。下面是郵編區號查詢js+xml版的核心代碼:
  
  1、data.xml文件代碼(這里只列了5條,明白他的結構就可以):
  <?xml version="1.0" encoding="gb2312"?>
  <!-- 郵編區號數據 -->
  <MyData>
  <Item Province="北京" County="北京" Zipcode="100000" Areacode="010" />
  <Item Province="北京" County="通縣" Zipcode="101100" Areacode="010" />
  <Item Province="北京" County="昌平" Zipcode="102200" Areacode="010" />
  <Item Province="北京" County="大興" Zipcode="102600" Areacode="010" />
  <Item Province="北京" County="密云" Zipcode="101500" Areacode="010" />
  </MyData>
  
  2、index.htm文件代碼(這個就是主界面拉)
  <Html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  <title>js+xml的郵編區號查詢</title>
  <style type="text/Css">
  <!--
  body,td,th {
  font-size: 12px;}
  
  body {
  text-align:center;
  background-color:#fefefe;
  margin-left: 0px;
  margin-top: 0px;
  margin-right: 0px;
  margin-bottom: 0px;
  }
  .mainTable{
  background-color:#FFFFFF;border:1px solid #dddddd;
  }
  .foot{
  line-height:20px;text-align:left;
  }
  .foot a:link,.foot a:visited,.foot a:active{
  background-color: #f0f0f0;width:45px; height:20px;
  margin:5px 0px 0px 0px;padding:3px 3px 2px 3px;
  border-right:1px solid #cccccc;border-bottom:1px solid #cccccc;
  border-top:1px solid #f5f5f5;border-left:1px solid #f5f5f5;
  color:#000000;text-align:center;
  line-height:14px;font-size:12px;
  }
  .head td{
  font-size:14px; letter-spacing:2px;
  border-bottom:1px solid #dddddd;
  text-align:center;height:24px;
  FILTER:   }
  
  .Item{
  font-size:12px;height:20px;
  text-indent:5px;
  border-bottom:1px solid #dddddd;
  background-color:#fafafa;
  }
  
  .Over{
  font-size:12px;height:20px;
  text-indent:5px;
  border-bottom:1px solid #dddddd;
  background-color:#f5f5f5;
  }
  
  .SearchBar {
  font-size:12px; letter-spacing:2px;
  border-bottom:1px solid #dddddd;
  padding:5px 0px 3px 0px;
  margin:4px 0px 4px 0px;
  text-align:center;height:24px;
  FILTER: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#f5f5f5', endColorStr='#eeeeee', gradientType='0');
  }
  .SearchBar input.textfield{
  border-top:1px solid #dddddd;border-left:1px solid #dddddd;
  border-right:1px solid #ffffff;border-bottom:1px solid #ffffff;
  BACKGROUND-COLOR: #f5f5f5;line-height:18px;
  width:240px;HEIGHT: 22px;
  }
  .SearchBar span.button{
  BORDER: 1px outset #f0f0f0;
  BACKGROUND-COLOR: #fafafa;
  width:50px;HEIGHT: 20px;
  padding:3px 3px 2px 3px;
  cursor:hand;
  }
  -->
  </style>
  <script language="javascript">
  <!--
  function Data_Load(Key
Words,KeyField,regEXPType){
  var myXmlPath="data.xml"; //設置xml文件路徑
  var myHolder=document.getElementById("insertdiv");
  var myFoot=document.getElementById("footdiv");
  var myTableID="Table_";
  
  
  var myXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  myXmlDoc.async="false";
  myXmlDoc.load(myXmlPath);
  var xmlObj=myXmlDoc.documentElement;
  var myNodes = myXmlDoc.documentElement.childNodes;
  var myCount=0;
  var myPageSize=20;
  var myPageIndex=1;
  
  var myTable,myTr,myTd;
  for (var i=0;i<myNodes.length;i++){
  
  var myCheck=Data_Filter(KeyWords,myNodes(i).getAttribute(KeyField),regExpType);
  if(myCheck==true){
  myCount++;
  if((myCount-1)==(myPageIndex-1)*myPageSize){
  myTable=document.createElement("<table id='"+ myTableID + myPageIndex +"' style='display:none; width:100%;' border=0>");
  myTable.className="mainTable";
  myTr=myTable.insertRow();
  myTr.className="Head"; //設置表頭CSS
  myTd=myTr.insertCell();
  myTd.innerText="省份";
  myTd=myTr.insertCell();
  myTd.innerText="地區";
  myTd=myTr.insertCell();
  myTd.innerText="郵編";
  myTd=myTr.insertCell();
  myTd.innerText="區號";
  }
  
  myTr=myTable.insertRow();
  myTd=myTr.insertCell();
  myTr.className="Item"; //設置內容css
  myTd.innerText=myNodes(i).getAttribute("Province");
  myTd=myTr.insertCell();
  myTd.innerText=myNodes(i).getAttribute("County");
  myTd=myTr.insertCell();
  myTd.innerText=myNodes(i).getAttribute("Z  myTd=myTr.insertCell();
  myTd.innerText=myNodes(i).getAttribute("Areacode");
  
  myTr.attachEvent("onmou
SEOver",ItemOver);
  myTr.attachEvent("onmouseout",ItemOut);
  
  if(myCount==(myPageIndex)*myPageSize){
  myHolder.appendChild(myTable); //增加表格
  var mySpan=document.createElement("<span>");
  mySpan.innerHTML=" <a href='#' onClick='Javacript:PageChange(/""+ myTableID + myPageIndex +"/")'>第"+myPageIndex+"頁</a> ";
  myFoot.appendChild(mySpan);
  myPageIndex++;
  }
  }
  
  }
  if(myCount>0){
  if(myCount>(myPageIndex-1)*myPageSize&&myCount!=myPageIndex*myPageSize){
  myHolder.appendChild(myTable); //增加表格
  var mySpan=document.createElement("<span>");
  mySpan.innerHTML=" <a href='#' onClick='javacript:PageChange(/""+ myTableID + myPageIndex +"/")'>第"+myPageIndex+"頁</a> ";
  myFoot.appendChild(mySpan);
  myPageIndex++;
  }
  
  var myInfo=document.createElement("<span>");
  var myPageNum=(myPageIndex*myPageSize>myCount)?(myPageIndex-1):myPageIndex;
  myInfo.innerHTML="共計【"+myCount+"】條信息,每頁"+ myPageSize+"條,分"+myPageNum+"頁顯示。";
  myFoot.appendChild(myInfo);
  PageChange(myTableID +"1");
  }else{
  var myInfo=document.createElement("<span>");
  myInfo.innerHTML=" 對不起,沒找到任何相關數據...";
  myFoot.appendChild(myInfo);
  }
  document.getElementById("Waiting").style.display="none";
  }
  
  function Data_Filter(inputWords,inputFieldValue,regExpType){
  inputWords=inputWords.replace(/(^/s*)(/s*$)/g, "");
  inputFieldValue=inputFieldValue.replace(/(^/s*)(/s*$)/g, "");
  switch(regExpType){
  case 0: //等于
  if(inputWords==inputFieldValue){
  return true;
  }else{
  return false;
  }
  break;
  case 1: //包含
  if(inputFieldValue.indexOf(inputWords)>-1){
  return true;
  }else{
  return false;
  }
  break;
  case 2: //以...開頭
  if(inputFieldValue.substring(0,inputWords.length)==inputWords){
  return true;
  }else{
  return false;
  }
  break;
  case 3: //以...結尾
  if(inputFieldValue.substring(inputFieldValue.indexOf(inputWords),inputFieldValue.length)==inputWords){
  return true;
  }else{
  return false;
  }
  break;
  default: //等于
  if(inputWords==inputFieldValue){
  return true;
  }else{
  return false;
  }
  break;
  }
  
  return false;
  }
  
  function PageChange(showID){
  var myHolder=document.getElementById("insertdiv");
  for(var i=0;i<myHolder.childNodes.length; i++){
  var myNode = myHolder.childNodes[i];

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 信阳市| 昭苏县| 高尔夫| 铅山县| 宝坻区| 屏东市| 秦安县| 黔南| 江孜县| 鄂托克旗| 南投县| 昭平县| 丰原市| 延寿县| 清河县| 贞丰县| 松桃| 鄂尔多斯市| 连城县| 高雄市| 北辰区| 府谷县| 长武县| 多伦县| 灵武市| 凤阳县| 尉犁县| 穆棱市| 渭源县| 栖霞市| 蒙城县| 遵义县| 沈阳市| 孟津县| 富蕴县| 怀集县| 名山县| 建宁县| 乃东县| 铅山县| 炉霍县|