zoukankan
html css js c++ java
Jquery 之AJAX 无刷新下拉菜单
Jquery 之AJAX 无刷新下拉菜单
<!
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
runat
="server"
>
<
title
>
无标题页
</
title
>
<
script
src
="js/jquery.js"
type
="text/javascript"
></
script
>
<
script
type
="text/javascript"
>
$(document).ready(
function
()
{
document.getElementById(
"
dListCity
"
).options.add(
new
Option(
"
---
"
,
"
-1
"
));
$.ajax(
{
type:
"
get
"
,
url:
"
getcountry.aspx
"
,
dataType:
"
html
"
,
data:
""
,
error:
function
()
{
}
,
success:
function
(data)
{
document.getElementById(
"
countryId
"
).length
=
0
;
if
(data
!=
""
)
{
var
allArray
=
data.split(
"
#
"
)[
0
];
var
allArray1
=
data.split(
"
#
"
)[
1
];
var
thisarray1
=
allArray.split(
"
,
"
);
var
thisarray2
=
allArray1.split(
"
,
"
);
}
for
(
var
i
=
1
;i
<
thisarray1.length
-
1
;i
++
)
{
document.getElementById(
"
countryId
"
).options.add(
new
Option(thisarray1[i].toString(),thisarray2[i].toString()));
}
}
}
);
$.ajax(
{
type:
"
get
"
,
url:
"
getprovince.aspx
"
,
dataType:
"
html
"
,
data:
""
,
error:
function
()
{
}
,
success:
function
(data)
{
document.getElementById(
"
dListProvince
"
).length
=
0
;
if
(data
!=
""
)
{
var
allArray
=
data.split(
"
#
"
)[
0
];
var
allArray1
=
data.split(
"
#
"
)[
1
];
var
thisarray1
=
allArray.split(
"
,
"
);
var
thisarray2
=
allArray1.split(
"
,
"
);
}
for
(
var
i
=
0
;i
<
thisarray1.length
-
1
;i
++
)
{
document.getElementById(
"
dListProvince
"
).options.add(
new
Option(thisarray1[i].toString(),thisarray2[i].toString()));
}
document.getElementById(
'
dListProvince
'
).selectedIndex
=
document.getElementById(
'
hidProviceId
'
).value
==
''
?
0
: document.getElementById(
'
hidProviceId
'
).value
-
1
;
//
保存选择过的省份
getCityByProvince(
1
);
}
}
);
}
);
function
getCityByProvince(value)
{
$.ajax(
{
type:
"
get
"
,
url:
"
Notice.aspx?provinceId=
"
+
value,
dataType:
"
html
"
,
data:
""
,
error:
function
()
{
}
,
success:
function
(data)
{
document.getElementById(
"
dListCity
"
).length
=
0
;
if
(data
!=
""
)
{
var
allArray
=
data.split(
"
#
"
)[
0
];
var
allArray1
=
data.split(
"
#
"
)[
1
];
var
thisarray1
=
allArray.split(
"
,
"
);
var
thisarray2
=
allArray1.split(
"
,
"
);
}
for
(
var
i
=
0
;i
<
thisarray1.length
-
1
;i
++
)
{
document.getElementById(
"
dListCity
"
).options.add(
new
Option(thisarray1[i].toString(),thisarray2[i].toString()));
}
}
}
)
}
</
script
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<
div
>
<
tr
>
Country:
<
select
id
="countryId"
onblur
="document.getElementById('hidCountryId').value = this.value;document.getElementById('hidCountryId').value = document.getElementById('countryId').value;"
></
select
>
Province:
<
select
id
="dListProvince"
onchange
="getCityByProvince(this.value);"
onblur
="document.getElementById('hidProviceId').value = this.value;document.getElementById('hidCityId').value = document.getElementById('dListCity').value;"
></
select
>
City:
<
select
id
="dListCity"
onclick
="document.getElementById('hidCityId').value = this.value;"
></
select
>
<
input
id
="hidCountryId"
type
="hidden"
style
=" 12px"
/>
<
input
id
="hidProviceId"
type
="hidden"
style
=" 2px"
/>
<
input
id
="hidCityId"
type
="hidden"
style
=" 7px"
/>
<
br
/>
</
tr
>
</
div
>
</
form
>
</
body
>
</
html
>
查看全文
相关阅读:
神舟笔记本反厂后带来的惊喜与郁闷
如今是否还要坚持asp.net,坚持程序员这个不怎么光荣的称号
严援朝的一句名言
一个专科生程序员的痛苦境遇
overflow:hidden 文本不在over 范围,也不显示
困扰很久的问题
未来已来,4K激活字库产业新世代
4K超高清,为字库产业,打开了数字家电的大门
2012中文字库简单统计与分类
图说字王数格纵系列
原文地址:https://www.cnblogs.com/xiaobaigang/p/1154640.html
最新文章
数据结构>哈希表 小强斋
排序>选择排序 小强斋
排序>插入排序 小强斋
排序>概述 小强斋
排序>选择排序 小强斋
排序>交换排序 小强斋
排序>概述 小强斋
【设计模式】穿什么有这么重要? 装饰模式
unix编程艺术的设计原则
mysql blob字段存储图片操作示例
热门文章
java swing的背景图片按比例缩放
C#枚举
java networking
C++ Versus ObjectiveC
self dismissModalViewControllerAnimated:YES 无效
【设计模式系列】行为型模式之Visitor模式
【算法设计】求逆序数
你跟对老板了吗?
闲来无聊,随便看下asp.net Mvc 的收获
Google 搜不出变化的东西
Copyright © 2011-2022 走看看