首页 新闻 会员 周边 捐助

html <span> 控件取值

0
悬赏园豆:5 [已解决问题] 解决于 2015-04-07 13:08

用.net Ajax 做县乡村 三级联动下拉选项

 

html页面:

<div align="left">
                            <span id="span_Province">
                                <asp:DropDownList ID="Drop_Xian" runat="server" onchange="ChangeSlect(this.options[this.selectedIndex].value,this.name)"
                                    OnDataBound="Drop_Province_DataBound">
                                </asp:DropDownList></span>
                                <span id="span_Xiang" runat="server"></span>
                                <span id="span_Cun" runat="server"></span>
                        </div>
 function GetZoneInfo(zoneID, level) {
         $.ajax({
             type: "POST",
             url: "../../Ajax/RegionCode.ashx?type=GetZoneInfo" + "&zoneID=" + zoneID + "&level=" + level,
             data: "",
             beforeSend: function () { },
             success: function (msg) {
                 switch (level) {
                     case 1:
                         $("#span_Xiang").html(msg);
                         break;
                     case 2:
                         $("#span_Cun").html(msg);
                         break;
                     default:
                         break;
                 }

             },
             error: function () { alert("网络繁忙,请稍后再试。"); },
             complete: function () { }
         });
     }

 


Ajax:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.Services;
using System.Text;
using RM.Busines;
using System.Web.SessionState;

namespace RM.Web.Ajax
{
    /// <summary>
    /// Handler1 的摘要说明
    /// </summary>
    public class RegionCode : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            if (!string.IsNullOrEmpty(context.Request.QueryString["type"]))
            {
                switch (context.Request.QueryString["type"])
                {
                    case "GetZoneInfo":
                        GetZoneInfo(context);
                        break;
                    default:
                        break;
                }
            }
        }

        public void GetZoneInfo(HttpContext context)
        {
            if (!string.IsNullOrEmpty(context.Request.QueryString["zoneID"]) && !string.IsNullOrEmpty(context.Request.QueryString["level"]))
            {
                string controlName = "";
                switch (context.Request.QueryString["level"])
                {
                    case "1":
                        controlName = "Drop_Xiang";
                        break;
                    case "2":
                        controlName = "Drop_Cun";
                        break;
                    default:
                        return;
                }

                DataTable dt = DataFactory.SqlDataBase().GetZoneInfo(context.Request.QueryString["zoneID"]);

                StringBuilder sb = new StringBuilder();
                sb.Append(String.Format("<select Name=\"{0}\" id=\"{1}\" onchange=\"ChangeSlect(this.options[this.selectedIndex].value,this.name)\">", controlName, controlName));
                sb.Append("<option value=\"0\">未选择</option>");
                foreach (DataRow row in dt.Rows)
                {

                    sb.Append("<option value=\"");
                    sb.Append(row["RegionCode"].ToString());
                    sb.Append("\">");
                    sb.Append(row["RegionName"].ToString());
                    sb.Append("</option>");
                }
                sb.Append("</select>");
                context.Response.Write(sb.ToString());
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

html 页面可也接收到AJAX的返回值,我想取

<span id="span_Xiang" runat="server"></span>
 <span id="span_Cun" runat="server"></span>
这两个控件的当前选中值,如何取?
有类似 于 span_Cun.SelectValue
 
天水Lv的主页 天水Lv | 初学一级 | 园豆:41
提问于:2015-04-07 10:15
< >
分享
最佳答案
0

你是希望在后台取还是前台?

如果是前台(js),则:$("#span_Xiang select")获得select对象

如果是后台(.net),则麻烦点。

1、通过request来获取

2、给这些span增加select,然后。。。更麻烦,还是用request来获取吧。

收获园豆:5
519740105 | 大侠五级 |园豆:5810 | 2015-04-07 12:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册