jquery 下拉框联动(1)

由于项目中好多地方要用到两个同样的下拉框,也避免多个页面写同样的方法,采用jquery来实现很方便,

在每个调用的页面只需写js就可以实现。

方法一:jquery ajax

html 页面

<div ID="ddlSummary">
     <select id="ddlCompany">
     </select>
      <select id="ddlFund">
     </select>
  </div>

 

js:

<script type="text/javascript">

//初始化加载基金公司
        $.ajax({
            url: "/Inc/Ajax_Data.aspx",
            type: "get",
            dataType: "html",
            cache: false,
            data: "method=GetFundCompany",
            success: function(html) {
            $("#ddlCompany").append(html);
            }
           });

 

       $(document).ready(function() {


            $('#ddlCompany').change(function() {//变更事件

             GetData();

            });
           });

 

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

 

cs文件:

 

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using AASmart.Financier.Interface;

namespace AASmart.Financier.Web.Inc.System
{
    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 "GetFundNetVal":
                        result = GetFundNetVal();
                        break;
                    case "GetFundCompany":
                          result = GetFundCompany();
                          break;
                    case "GetFundList":
                         result = GetFundListInfo();
                         break;
                }
            }
            Response.Write(result);
        }

 

  public string GetFundCompany()
  {
   string html = string.Empty;
   DataSet ds =GetList();
   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"];
   DataSet ds = GetData();
   string ret = "";
   //ret = "0-请选择基金..";
   foreach (DataRow dr in ds.Tables[0].Rows)
   {
    ret += "<option  value=/"" + dr["jcode"] + "/">" + dr["title"] + "</option>";
   }
   return ret;
  }

        
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值