?
快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

新蒲京澳門賭場網站:jQuery JSON 無刷新三級聯動

?

asp:DropDownList ID="ddl1" runat="server" Width="100px" >a新蒲京澳門賭場網站sp:DropDownList>

asp:DropDownList ID="ddl2" runat="server" Width="100px" >asp:DropDownList>

asp:DropDownList ID="ddl3" runat="server" Width="100px" >asp:DropDownList>

js:

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

script type="text/javascript">

$(document).ready(function () {

GetA();

$("#ddl1").change(function () { GetB();});

$("#ddl2").change(function () { GetC();});

});

function GetA()

{

$("#ddl1").html("");

$("#ddl1").append("請選擇...");

//$("select[name$=ddl1] > option:selected").remove();

var strId = 0;

$.getJSON("LoadClass.ashx?ddlId=" + strId, function (data) {

for (var i = 0; i "select[name$=ddl1]").append($("").val(data[i].ID).html(data[i].Cname));

};

GetB();

});

}

function GetB()

{

$("#ddl2").html(""); $("#ddl3").html("");

var strId = $("#ddl1").attr("value");

if (strId != 0) {

$.getJSON("LoadClass.ashx?ddlId=" + strId, function (data) {

for (var i = 0; i "select[name$=ddl2]").append($("").val(data[i].ID).html(data[i].Cname));

};

Ge新蒲京澳門賭場網站tC();

});

}

}

function GetC()

{

$("#ddl3").html("");

var strId = $("#ddl2").attr("value");

if (strId != 0) {

$.getJSON("LoadClass.ashx?ddlId=" + strId, function (data) {

for (var i = 0; i "select[name$=ddl3]").append($("").val(data[i].ID).html(data[i].Cname));

};

}新蒲京澳門賭場網站);

}

}

script>

LoadCl新蒲京澳門賭場網站ass.ashx:

@ WebHandler Language="C#" Class="LoadClass" %>

using System;

using System.Web;

using System.Text;

using System.Data;

public class LoadClass : IHttpHandler新蒲京澳門賭場網站 {

public void ProcessRequest (HttpContext context) {

// 數組[{"ID":"275","Cname":"A1"},{"ID":"319","Cname":"A2"},{"ID":"322","Cname":"A3"}]

int strId = Convert.ToInt32(context.Request["ddlId"]);

string strSQL = "select * from Class where parent_Ptr=" + strId + "order by classOrder asc ";

db d = new db();

DataTable dt = d.getDT(strSQL);

StringBuilder strClass = new StringBuilder();

if (dt != null)

{

strClass.Append("[");

for (int i = 0; i "{");

strClass.Append("\"ID\":\"" + dt.Rows[i]["id"].ToString() + "\",");

strClass.Append("\"Cname\":\"" + dt.Rows[i]["classCname"].ToString() + "\"");

if (i != dt.Rows.Count - 1)

{

strClass.Append("},");

}

}

}

strClass.Append("}");

strClass.Append("]");

context.Response.ContentType = "application/json";

context.Response.ContentEncoding = Encoding.UTF8;

context.Response.Write(strClass.ToString());

context.Response.End();

}

public bool IsReusable {

get {

return false;

}

}

}

留意:

//后臺只能獲取value值,不能直接獲取text,必要經由過程js、控件中轉

//結果:275 276 277

Label1.Text = Request.Form[ddl1.UniqueID] + " "

+ Request.Form["ddl2"] + " "

+ Request.Form[ddl3.ClientID.WordStr("_", "___FCKpd___7quot;)] ;

碰到的問題:

下拉框text的值經由過程HiddenField控件中轉

asp:HiddenField ID="HiddenField1" runat="server" />

asp:HiddenField ID="HiddenField2" runat="server" />

asp:HiddenField ID="HiddenField3" runat="server" />

把選中下拉框的值付與暗藏控件中:

script type="text/javascript">

var Key1 = $("#ddl1>option:selected").val();

$('#HiddenField1').val(Key1);

var Key2 = $("#ddl2>option:selected").val();

$('#HiddenField2').val(Key2);

var Key3 = $("#ddl3>option:selected").val();

$('#HiddenField3').val(Key3);

script>

選擇下拉框后 動態賦值到HiddenField 控件中的值 無法與下拉框選中的值相對應!

可能與初始化有關,賦值這段代碼應該放到什么地方呢?或者有什么好的措施,迎接評論爭論?

轉自:http://www.cnblogs.com/zengxiangzhan/archive/2010/02/21/1670646.html

免責聲明:以上內容源自網絡,版權歸原作者所有,如有侵犯您的原創版權請告知,我們將盡快刪除相關內容。

您可能還會對下面的文章感興趣:

快三平台开户