Ajax+jQuery 实现菜单联动

本文介绍了一种使用Ajax技术动态更新Web页面中下拉列表的方法。通过两次Ajax请求分别获取基金公司列表和根据所选公司动态获取基金列表,实现了用户交互过程中的数据实时更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

页面js:

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>

 <script type="text/javascript">
        $.ajax({
            url: "/Ajax_Data.aspx",
            type: "get",
            dataType: "html",
            cache: false,
            data: "method=GetFundCompany",
            success: function(html) {
            $("#ddlCompany").append(html);
            }
           });

           $(document).ready(function() {
           $('#CombDetailDiv').hide();
          
           var ret = "<option value='0'>请选择基金..</option>";
           $("#ddlFund").append(ret);
            $('#ddlCompany').change(function() {
             GetData();
            });
           });

           function GetData() {
           var id = $('#ddlCompany').val();
           $.ajax({
            url: "/Inc/System/Ajax_Data.aspx",
            type: "get",
            dataType: "html",
            cache: false,
            data: "method=GetFundList&ID=" + id,
            success: function(html) {
             $("#ddlFund").empty();//清空
             $("#ddlFund").append(html);
            }
           });
           }

 </script>  

 

页面:

<div>

<asp:DropDownList ID="ddlCompany" runat="server" Width="220px">
     </asp:DropDownList>

<asp:DropDownList ID="ddlFund" runat="server" Width="220px">
     </asp:DropDownList>

</div>

 

Ajax_Data.aspx文件

public partial class Ajax_Data : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string result = "";
            string method = Request["method"];
            if (!string.IsNullOrEmpty(method))
            {
                switch (method)
                {
                    case "hello":
                        result = hello();
                        break;
                    case "GetFundNetVal":
                        result = GetFundNetVal();
                        break;
     case "GetFundCompany":
      result = GetFundCompany();
      break;
     case "GetFundList":
      result = GetFundListInfo();
      break;
                }
            }
            Response.Write(result);
        }


        string hello()
        {
            string jcode = Request["Jcode"];
            return jcode;
        }

  public string GetFundCompany()
  {
   string html = "<option value='0'>请选择基金公司..</option>";
   DataSet ds =BusinessFactory.Common.GetList("GetFundCompany", new object[] { 7, 309 });
   foreach (DataRow dr in ds.Tables[0].Rows)
   {
    html += "<option  value=/"" + dr["id"] + "/">" + dr["CName"] + "</option>";
   }
   return html;
  }

  public string GetFundListInfo()
  {
   string ClassId=Request["ID"];
   string ret = "<option value='0'>请选择基金..</option>";
   if(ClassId=="0")
    return ret;

   DataSet ds = BusinessFactory.Fund.GetList("GetFundNameList", new object[] { ClassId });
   //ret = "0-请选择基金..";
   foreach (DataRow dr in ds.Tables[0].Rows)
   {
    ret += "<option  value=/"" + dr["jcode"] + "/">" + dr["title"] + "</option>";
   }
   return ret;
  }

        public string GetFundNetVal()
        {
            string jCode = Request["Jcode"];
            string Date = "2010-2-22";
            string ColumnName = "ddate";
            DataSet ds = BusinessFactory.Fund.GetList("GetFundNetValAndDate", new object[] { jCode, Date });
            string value = "0";
            foreach (DataRow dr in ds.Tables[0].Rows)
                value = dr[ColumnName].ToString();
            if (ColumnName.ToLower() == "ddate")
            {
                if (value == "0")
                    value = Date;
                else
                    value = Convert.ToDateTime(value).ToShortDateString();
            }
            return value;
        }
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值