zoukankan      html  css  js  c++  java
  • Jquery 之AJAX 无刷新下拉菜单

    Jquery 之AJAX  无刷新下拉菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        
    <title>无标题页</title>
        
    <script src="js/jquery.js" type="text/javascript"></script>    
     
    <script type="text/javascript">
            $(document).ready(
    function(){
                 document.getElementById(
    "dListCity").options.add(new Option("---","-1")); 
                 $.ajax(
    {
                    type:
    "get",
                    url:
    "getcountry.aspx",
                    dataType:
    "html",
                    data:
    "",
                    error:
    function(){
                    }
    ,
                    success:
    function(data){
                        document.getElementById(
    "countryId").length = 0;
                        
    if(data != "")
                        
    {
                            
    var allArray = data.split("#")[0];
                            
    var allArray1 = data.split("#")[1];
                            
    var thisarray1=allArray.split(",");
                            
    var thisarray2=allArray1.split(","); 
                        }

                        
    for(var i=1;i<thisarray1.length-1;i++)
                        
    {
                            document.getElementById(
    "countryId").options.add(new Option(thisarray1[i].toString(),thisarray2[i].toString()));                        
                        }
                        
                    }

                }
    );
                
                $.ajax(
    {
                    type:
    "get",
                    url:
    "getprovince.aspx",
                    dataType:
    "html",
                    data:
    "",
                    error:
    function(){
                    
                    }
    ,
                    success:
    function(data){
                        document.getElementById(
    "dListProvince").length = 0;
                        
    if(data != "")
                        
    {
                            
    var allArray = data.split("#")[0];
                            
    var allArray1 = data.split("#")[1];
                            
    var thisarray1=allArray.split(",");
                            
    var thisarray2=allArray1.split(","); 
                            
                        }

                        
    for(var i=0;i<thisarray1.length-1;i++)
                        
    {
                           
                            document.getElementById(
    "dListProvince").options.add(new Option(thisarray1[i].toString(),thisarray2[i].toString()));   
                            
                                             
                        }
                        
                        document.getElementById(
    'dListProvince').selectedIndex = document.getElementById('hidProviceId').value=='' ? 0 : document.getElementById('hidProviceId').value-1;//保存选择过的省份     
                        getCityByProvince(1);                           
                    }

                }
    );
            }
    );               
            
            
    function getCityByProvince(value)
            
    {
                $.ajax(
    {
                    type:
    "get",
                    url:
    "Notice.aspx?provinceId="+value,
                    dataType:
    "html",
                    data:
    "",
                    error:
    function(){
                    
                    }
    ,
                    success:
    function(data){
                        document.getElementById(
    "dListCity").length = 0;
                        
    if(data != "")
                        
    {
                            
    var allArray = data.split("#")[0];
                            
    var allArray1 = data.split("#")[1];
                            
    var thisarray1=allArray.split(",");
                            
    var thisarray2=allArray1.split(","); 
                                                }

                        
    for(var i=0;i<thisarray1.length-1;i++)
                        
    {
                            document.getElementById(
    "dListCity").options.add(new Option(thisarray1[i].toString(),thisarray2[i].toString()));                        
                        }

                      
                    }

                }
    )
            }
                  
            
        
    </script>
    </head>
    <body>
        
    <form id="form1" runat="server" >
         
    <div>
            
    <tr>
            Country:
    <select id="countryId" onblur="document.getElementById('hidCountryId').value = this.value;document.getElementById('hidCountryId').value = document.getElementById('countryId').value;"></select>
            Province:
    <select id="dListProvince" onchange="getCityByProvince(this.value);" onblur="document.getElementById('hidProviceId').value = this.value;document.getElementById('hidCityId').value = document.getElementById('dListCity').value;"></select>
            City:
    <select id="dListCity" onclick="document.getElementById('hidCityId').value = this.value;"></select>
       
            
    <input id="hidCountryId" type="hidden" style=" 12px" />
            
    <input id="hidProviceId" type="hidden"  style=" 2px" />
            
    <input id="hidCityId" type="hidden" style=" 7px" />
            
    <br />
            
    </tr>
     
    </div>
        
    </form>
    </body>
    </html>
  • 相关阅读:
    Unity多线程(Thread)和主线程(MainThread)交互使用类——Loom工具分享
    一种Unity2D多分辨率屏幕适配方案
    Unity 2D骨骼动画2:创建真实动画
    Unity2d 骨骼动画1:介绍
    Unity2d 骨骼动画3:介绍Mecanim和脚本
    Unity2D研究院之自动生成动画、AnimationController、Prefab(一)
    mongochef如何链接有权限的mongodb3.x数据库
    moogodb3.x总结
    mongodb3.x用户角色
    MongoDB 基础 -安全性-(权限操作)
  • 原文地址:https://www.cnblogs.com/xiaobaigang/p/1154640.html
Copyright © 2011-2022 走看看