`
a495863099
  • 浏览: 40348 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

省、市、地区联动选择实用脚本

阅读更多
      省、市、区三级级联使用脚本,效果图如下:
     
    
       范例代码见附件,其中核心脚本如下:
 function PCAS(){
	  this.SelP=document.getElementsByName(arguments[0])[0];
	  this.SelC=document.getElementsByName(arguments[1])[0];
	  this.SelA=document.getElementsByName(arguments[2])[0];
	  this.DefP=this.SelA?arguments[3]:arguments[2];
	  this.DefC=this.SelA?arguments[4]:arguments[3];
	  this.DefA=this.SelA?arguments[5]:arguments[4];
	  this.SelP.PCA=this;this.SelC.PCA=this;
	  this.SelP.onchange=function()
	  {
	  	PCAS.SetC(this.PCA)
	  };
	  if(this.SelA)
	     this.SelC.onchange=function()
	     {
		    PCAS.SetA(this.PCA)
	     };
	  PCAS.SetP(this)
	};
	
	PCAS.SetP=function(PCA)
	{
		for(i=0;i<PCAP.length;i++)
		{
			PCAPT=PCAPV=PCAP[i];
			if(PCAPT==SPT)
				PCAPV="";
				PCA.SelP.options.add(new Option(PCAPT,PCAPV));
				if(PCA.DefP==PCAPV)
					PCA.SelP[i].selected=true
		}
		PCAS.SetC(PCA)
	};
		
	PCAS.SetC=function(PCA)
	{
		PI=PCA.SelP.selectedIndex;
		PCA.SelC.length=0;
		for(i=1;i<PCAC[PI].length;i++)
		{
			PCACT=PCACV=PCAC[PI][i];
			if(PCACT==SCT)
				PCACV="";
			PCA.SelC.options.add(new Option(PCACT,PCACV));
			if(PCA.DefC==PCACV)
				PCA.SelC[i-1].selected=true
		}
		if(PCA.SelA)
			PCAS.SetA(PCA)
	 };
	
	PCAS.SetA=function(PCA)
	{
		PI=PCA.SelP.selectedIndex;
		CI=PCA.SelC.selectedIndex;
		PCA.SelA.length=0;
		for(i=1;i<PCAA[PI][CI].length;i++)
		{
			PCAAT=PCAAV=PCAA[PI][CI][i];
			if(PCAAT==SAT)
				PCAAV="";
			PCA.SelA.options.add(new Option(PCAAT,PCAAV));
			if(PCA.DefA==PCAAV)
				PCA.SelA[i-1].selected=true
		 }
	}

     更多实用脚本可访问http://www.popub.net
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics