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
>
查看全文
相关阅读:
docker学习笔记及hadoop集群搭建
Zookeeper+Kafka+Storm+HDFS实践
zookeeper集群搭建
scala学习笔记——特质
scala学习笔记-集合
scala学习笔记-隐式转换和隐式参数
RDD 重新分区,排序 repartitionAndSortWithinPartitions
scala学习笔记——操作符
JAVA基础系列(一) 概述与相关概念
网络收藏夹
原文地址:https://www.cnblogs.com/xiaobaigang/p/1154640.html
最新文章
Windows Phone 解析手机型号DeviceStatus.DeviceName
(C#)程序员必读的一些书籍
Windows Phone 提升开发效率(一)使用d:DataContext添加设计时Binding
Windows Phone 修改系统定义的资源颜色
C# 通过服务启动窗体(把窗体添加到服务里)实现用户交互的windows服务[转发]
c# 列举所有窗口和子窗口
HtmlAgilityPack中通过sibling才能得到对应的InnerText和form,option等tag的子节点
linux编译php的c扩展
MySQL学习笔记
小程序开发之搭建WebSocket的WSS环境(Apache+WorkerMan框架+PHP)
热门文章
PHP获取远程和本地文件信息(汇总)
一个通用的抽奖算法源码(适用于大转盘刮刮乐)
Linux的那点事
PHP开发笔记(三)关于PHP伪静态的问题总结
CSS 中文字体 Unicode 编码表
IIS 7.0、IIS 7.5 和 IIS 8.0 使用的 HTTP 状态代码【转载自微软官方】
PHP开发笔记(一)
关于SSL证书配置、升级的一些问题总结
hue学习手册
Quartz学习笔记
Copyright © 2011-2022 走看看