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
>
查看全文
相关阅读:
Java基础16(Java8的其它新特性)
Java基础15(反射机制)
Java基础14(网络编程)
tensorflow.keras
递归算法
tensorfolw学习笔记——张量、微分、自定义训练、keras
python可变长参数、key-only参数之收集和解包参数
20200909- 集群迁移记录
20200909--记一次发布流程
20200909----开发沟通提效记录
原文地址:https://www.cnblogs.com/xiaobaigang/p/1154640.html
最新文章
20200604自动化功能测试
9.时间日期日历及错误异常处理
8.file方法与os
7.函数和模块
10.面向对象(类、对象、属性及方法)
14.mysql+mysqlconnector
首次登录与在线求助man page
字典:当索引不好用时
主机规划与磁盘分区
关键的“构建”决策
热门文章
三思而后行:前期准备
Linux如何学习
使用字符串
列表和元组
快速改造:基础知识
用隐喻来更充分地理解软件开发
重定向和转发的区别
maven
04-springMVC(中)
03-springMVC(上)
Copyright © 2011-2022 走看看