首页 > 学院 > 开发设计 > 正文

利用ProtoType框架完成的一个下拉框(asp:DropDownList)联动的AJAX例子

2019-11-18 16:48:02
字体:
来源:转载
供稿:网友

最近终于有时间研究研究Ajax了.看了一些AJAX的介绍.
PRotoType框架完成的一个下拉框(asp:DropDownList)联动的AJAX的小例子,和初学者分享一下.

代码下载


<script language="javaScript" type="text/Javascript" >
<!--

function goCity()
{
        var url = "AreaHandler.ashx";
        var father= $F('<%=ddlProvince.ClientID%>')
        var pars = "ddl=province&father=" +father;
        var myAjax = new Ajax.Request(
                    url,
                    {method: 'get', parameters: pars, onComplete: LoadCity}
                    );
         
               
}

function goArea()
{

    var url = "AreaHandler.ashx";
   
    var father= $F('<%=ddlCity.ClientID%>')
            var pars = "ddl=city&father=" +father;
        var myAjax = new Ajax.Request(
                    url,
                    {method: 'get', parameters: pars, onComplete: LoadArea}
                    );

}

  function LoadCity(originalRequest)
    {
    var result=originalRequest.responseText;
    var ddl=$('<%=ddlCity.ClientID%>')
       FillDropDown(ddl,result);
        if (ddl.length == 0){
        $('<%=ddlArea.ClientID%>').length=0;
       $('<%=ddlArea.ClientID%>').disabled = 1;
       ddl.disabled = 'true';
             }
       else{
   $('<%=ddlArea.ClientID%>').disabled = 0;
       ddl.disabled = 0;
       goArea();
    }
    }
  function LoadArea(originalRequest)
    {
     var result=originalRequest.responseText;
     var ddl=$('<%=ddlArea.ClientID%>')
       FillDropDown(ddl,result);
      
       if (ddl.length == 0)
         ddl.disabled =1;
         esle
         ddl.disabled =0;
 
      
    }
   
   
   function FillDropDown(objDDL,result ){
      var piArray = result.split(",");
          
     objDDL.length=0;
    for(var i=0;i<piArray.length;i++)
   {
   var ary1 = piArray[i].toString().split("|");
   if (ary1.length >1 )
    objDDL.options.add(new Option(ary1[1].toString(),ary1[0].toString()));
  }
    }
 
-->
</script>

http://www.VEVb.com/rippleyong/archive/2006/12/18/596015.html


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表