Ajax级联菜单实例代码
1.ajax.html
<!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>ajax</title>
<script type="text/javascript">
function loadxmldoc(txt) {
var xmlhttp;
if (window.xmlhttprequest) {// code for ie7+, firefox, chrome, opera, safari
xmlhttp = new xmlhttprequest();
}
else {// code for ie6, ie5
xmlhttp = new activexobject("microsoft.xmlhttp");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {
var citys = xmlhttp.responsetext.split(',');
document.getelementbyid("citys").length = 1;
for (i = 0; i < citys.length - 1; i++) {
document.getelementbyid("citys").add(new option(citys[i], citys[i]));
}
// document.getelementbyid("mydiv").innerhtml = xmlhttp.responsetext;
}
}
xmlhttp.open("get","ajax/getdata.aspx?pro="+txt, true);
xmlhttp.send();
}
</script>
</head>
<body>
<h2>ajax</h2>
<select id="select1" onchange="loadxmldoc(this.value)">
<option>请选择省份</option>
<option value="1">江苏</option>
<option value="2">上海</option>
</select>
<select id="citys">
<option>请选择城市</option>
</select>
<div id="mydiv"></div>
</body>
</html>
2.getdata.aspx.cs
using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
public partial class ajax_getdata : system.web.ui.page
{
protected void page_load(object sender, eventargs e)
{
string[] js=new string[]{"南京", "苏州", "常州" , "无锡" , "镇江"};
string pro=request.querystring["pro"];
if (pro == "1")
{
string temp = "";
for (int i = 0; i < js.length; i++)
{
temp = temp + js[i];
temp = temp + ",";
}
response.write(temp);
}
else
response.write("");
}
}
下一篇: 刘琰是怎么死的?污蔑皇帝惹怒圣上不得善终
推荐阅读
-
ThinkPHP使用心得分享-ThinkPHP + Ajax 实现2级联动下拉菜单_PHP
-
Django中使用jquery的ajax进行数据交互的实例代码
-
ajax完美实现两个网页 分页功能的实例代码_php实例
-
ThinkPHP使用心得分享-ThinkPHP + Ajax 实现2级联动下拉菜单_PHP教程
-
ajax php 聊天室实例代码(1/5)
-
jQuery实现可收缩展开的级联菜单实例代码_javascript技巧
-
Ajax异步上传文件实例代码分享
-
ASP.NET Ajax级联DropDownList实现代码
-
zTree插件之单选下拉菜单实例代码_javascript技巧
-
一个级联菜单代码学习及removeClass与addClass的应用_javascript技巧