ajax.net +jquery 無刷新三級聯(lián)動(dòng)的實(shí)例代碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Jquery1.7.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$.ajax({
type: "post",
contentType: "application/json",
url: "WebService1.asmx/loadprovince",
data: "{}",
success: function (result) {
var ping;
for (var i = 0; i < result.d.length; i++) {
ping += "<option value=" + result.d[i].provinceID + ">";
ping += result.d[i].provincename;
ping += "</option>";
}
$('#Select1').append(ping);
}
})
$('#Select1').change(function () {
//第二次選時(shí)要記得清空市和縣中的內(nèi)容
$('#Select2 option:gt(0)').remove();
$('#Select3 option:gt(0)').remove();
//在省的改變事件里綁定下一個(gè)下來列表(要失掉省的id)
$.ajax({
type: "post",
contentType: "application/json",
url: "WebService1.asmx/loadcity",
data: "{fatherid:'" + $('#Select1 option:selected').val() + "'}",
success: function (result) {
var str2;
for (var i = 0; i < result.d.length; i++) {
str2 += "<option value=" + result.d[i].cityID + ">";
str2 += result.d[i].cityname;
str2 += "</option>";
}
$('#Select2').append(str2);
}
})
})
$('#Select2').change(function () {
$('#Select3 option:gt(0)').remove();
$.ajax({
type: "post",
contentType: "application/json",
url: "WebService1.asmx/loadarea",
data: "{fatherid:'" + $('#Select2 option:selected').val() + "'}",
success: function (result) {
var str3;
for (var i = 0; i < result.d.length; i++) {
str3 += "<option value=" + result.d.areaID + ">";
str3 += result.d[i].areaname;
str3 += result.d[i].father;
}
$('#Select3').append(str3);
}
})
})
})
</script>
</head>
<body>
?。?BR> <select id="Select1">
<option>--請選擇--</option>
</select>
市:
<select id="Select2">
<option>--請選擇--</option>
</select>
縣:
<select id="Select3">
<option>--請選擇--</option>
</select>
</body>
</html>
webservice:
[WebMethod]//加載省
public List<Model.province> loadprovince()//為什么要用list因?yàn)檫@里出從前的值不可能一個(gè)實(shí)例是多個(gè)model實(shí)例,一個(gè)實(shí)例就是一條記載這樣做防止字段錯(cuò)誤
{
BLL.province bp = new BLL.province();
List<Model.province> list=bp.getlistModel();
return list;
}
[WebMethod]//加載市
public List<Model.city> loadcity(string fatherid)
{
BLL.city bc = new BLL.city();
List<Model.city> list = bc.getlistmodel(fatherid);
return list;
}
[WebMethod]//加載縣
public List<Model.area> loadarea(string fatherid)
{
BLL.area ba = new BLL.area();
List<Model.area> list = ba.getlistmodel(fatherid);
return list;
}
}
}
DAL--area
public System.Collections.Generic.List<Model.area> getlistmodel(string fatherid)
{
System.Collections.Generic.List<Model.area> list = new System.Collections.Generic.List<Model.area>();
DataTable dt = GetList("father=" + fatherid + "").Tables[0];
foreach (DataRow row in dt.Rows)
{
Model.area ma = new Model.area();
ma.areaID = row["areaID"].ToString();
ma.areaname = row["areaname"].ToString();
ma.father = row["father"].ToString();
list.Add(ma);
}
return list;
}
Dal--city
public System.Collections.Generic.List<Model.area> getlistmodel(string fatherid)
{
System.Collections.Generic.List<Model.area> list = new System.Collections.Generic.List<Model.area>();
DataTable dt = GetList("father=" + fatherid + "").Tables[0];
foreach (DataRow row in dt.Rows)
{
Model.area ma = new Model.area();
ma.areaID = row["areaID"].ToString();
ma.areaname = row["areaname"].ToString();
ma.father = row["father"].ToString();
list.Add(ma);
}
return list;
}
}
DAL-provience
public System.Collections.Generic.List<Model.province> getlistModel()
{
//將要查的內(nèi)容以實(shí)例的方式返回
//這里要做的就是要建立list并將list用model實(shí)例填滿,而model要用一個(gè)方法失掉數(shù)據(jù)并添加到model中
//建list實(shí)例
System.Collections.Generic.List<Model.province> list = new System.Collections.Generic.List<Model.province>();
//已經(jīng)有了的失掉數(shù)據(jù)的方法就不用自己寫了通過調(diào)用Getlist的方法操縱數(shù)據(jù)庫拿到數(shù)據(jù)
DataTable dt = GetList("").Tables[0];
//拿到數(shù)據(jù)后就需要將數(shù)據(jù)添加到model實(shí)例中了
foreach (DataRow row in dt.Rows)
{
//每一行都是個(gè)實(shí)例所以要將model的放在循環(huán)里面
Model.province mp = new Model.province();
mp.provinceID = row["provinceID"].ToString();
mp.provincename = row["provincename"].ToString();
list.Add(mp);//沒添加完一個(gè)實(shí)例都要放到list中
}
return list;
}
- PHP+Mysql+Ajax+JS實(shí)現(xiàn)省市區(qū)三級聯(lián)動(dòng)
- asp.net省市三級聯(lián)動(dòng)的DropDownList+Ajax的三種框架(aspnet/Jquery/ExtJs)示例
- AJAX省市區(qū)三級聯(lián)動(dòng)下拉菜單(java版)
- ajax實(shí)現(xiàn)無刷新省市縣三級聯(lián)動(dòng)
- ajax三級聯(lián)動(dòng)下拉菜單效果
- jquery+ajax實(shí)現(xiàn)省市區(qū)三級聯(lián)動(dòng)效果簡單示例
- jQuery ajax實(shí)現(xiàn)省市縣三級聯(lián)動(dòng)
- ajax三級聯(lián)動(dòng)的實(shí)現(xiàn)方法
- AJAX和WebService實(shí)現(xiàn)省市縣三級聯(lián)動(dòng)具體代碼
- ajax實(shí)現(xiàn)select三級聯(lián)動(dòng)效果
相關(guān)文章
asp.net 安全、實(shí)用、簡單的大容量存儲過程分頁
昨晚研究到2點(diǎn)多,對網(wǎng)絡(luò)上主流的分頁存儲過程大體看了一遍,但對安全以及如何使用很多文章都沒有過多的提及,而我要在這些文章的基礎(chǔ)上總結(jié)出一個(gè)比較實(shí)用的分頁存儲過程,方便大家在以后的項(xiàng)目中使用。2009-06-06.NET的基元類型包括什么及Unmanaged和Blittable類型詳解
這篇文章主要介紹了.NET的基元類型包括什么及Unmanaged和Blittable類型詳解,Unmanaged類型可以理解不涉及托管對象引用的值類型,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06瀏覽器窗口滾動(dòng)加載數(shù)據(jù)采用異步形式從后臺加載數(shù)據(jù)
在滾動(dòng)條距頂部距離(頁面超出窗口的高度)時(shí)采用異步形式從后臺加載數(shù)據(jù),下面是具體的實(shí)現(xiàn),希望對大家有所幫助2014-01-01FreeTextBox(版本3.1.6)在ASP.Net 2.0中使用方法
在ASP.Net 2.0中使用,只需要2個(gè)文件:FreeTextBox.DLL和ftb.imagegallery.aspx2009-11-11AspNetCore&MassTransit?Courier實(shí)現(xiàn)分布式事務(wù)的詳細(xì)過程
MassTransit?Courier是一種用于創(chuàng)建和執(zhí)行帶有故障補(bǔ)償?shù)姆植际绞聞?wù)的機(jī)制,它可以用于滿足本地事務(wù)的需求,也可以在分布式系統(tǒng)中實(shí)現(xiàn)分布式事務(wù),這篇文章主要介紹了AspNetCore&MassTransit?Courier實(shí)現(xiàn)分布式事務(wù),需要的朋友可以參考下2022-10-10Image顯示服務(wù)器上任意絕對路徑下的圖片(采用二進(jìn)制流實(shí)現(xiàn))
有這樣一個(gè)需求:數(shù)據(jù)庫中存儲的是照片所在的絕對路徑(可以不在系統(tǒng)所在路徑下),Image控件動(dòng)態(tài)加載路徑下的圖片,另類實(shí)現(xiàn)方法,感興趣的朋友可以參考下,或許本文對你學(xué)習(xí)二進(jìn)制流有所幫助2013-02-02Asp.Net 網(wǎng)站優(yōu)化系列之?dāng)?shù)據(jù)庫優(yōu)化 分字訣 分表(縱向拆分,橫向分區(qū))
上篇談了分庫,這一篇我們來分表2010-06-06ASP.Net2.0 GridView 多列排序,顯示排序圖標(biāo),分頁
ASP.Net2.0 GridView 多列排序,顯示排序圖標(biāo),分頁...2006-09-09