實(shí)現(xiàn)無(wú)刷新聯(lián)動(dòng)例子匯總
Iframe實(shí)現(xiàn)無(wú)刷新聯(lián)動(dòng)
iframe的無(wú)刷新其實(shí)是局部刷新,狀態(tài)欄的滾動(dòng)條還是會(huì)滾動(dòng),只是頁(yè)面不會(huì)閃爍,這是一種比較老的技術(shù)了,在處理的數(shù)據(jù)兩大的時(shí)候會(huì)比較慢,在本例中需要兩個(gè)頁(yè)面:index.aspx和frame.asapx,index.aspx用來(lái)顯示界面,其中有一個(gè)iframe標(biāo)記,指向frame.aspx頁(yè)用來(lái)顯示結(jié)果
index.aspx前臺(tái)代碼
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="_Default" %>
<!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 id="Head1" runat="server">
<title>無(wú)標(biāo)題頁(yè)</title>
<script type="text/javascript">
function Query() {
var ddlpro = document.getElementById('ddlPro');
var pro = ddlpro.options[ddlpro.selectedIndex].innerText;
if (pro != "") {
document.getElementById("iframe1").src = "frame.aspx?Pro=" + pro;
}
}
</script>
</head>
<body>
<form id="form2" runat="server">
<div>
<table border="1" cellpadding="3" cellspacing="0" width="600px">
<tr>
<td colspan="2" align="center">
Iframe實(shí)現(xiàn)局部刷新
</td>
</tr>
<tr>
<td>
省份名稱:
</td>
<td>
<select id="ddlPro" style="width: 201px">
<option value="湖北">湖北</option>
<option value="河北">河北</option>
<option value="廣東">廣東</option>
<option value="河南">河南</option>
</select>
<input id="Button3" type="button" value="查詢" onclick="Query()" />
</td>
</tr>
<tr>
<td>
顯示城市列表
</td>
<td>
<iframe src="frame.aspx" style="text-align: center" id="iframe1" width="100%"
height="100%" frameborder="0" scrolling="no" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
frame.aspx的前臺(tái)代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="frame.aspx.cs" Inherits="myframe" %>
<!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 id="Head1" runat="server">
<title>無(wú)標(biāo)題頁(yè)</title>
</head>
<body>
<form id="form2" runat="server">
<div>
<asp:DropDownList ID="ddlCity" runat="server" Width="179px">
</asp:DropDownList>
</div>
</form>
</body>
</html>
frame.aspx后臺(tái)代碼:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class myframe : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string pro = Request.QueryString["pro"];
switch (pro)
{
case "湖北":
this.ddlCity.Items.Clear();
this.ddlCity.Items.Add("武漢");
this.ddlCity.Items.Add("黃岡");
this.ddlCity.Items.Add("黃石");
this.ddlCity.Items.Add("襄樊");
break;
case "河北":
this.ddlCity.Items.Clear();
this.ddlCity.Items.Add("石家莊");
this.ddlCity.Items.Add("唐山");
this.ddlCity.Items.Add("承德");
this.ddlCity.Items.Add("邯鄲");
break;
case "廣東":
this.ddlCity.Items.Clear();
this.ddlCity.Items.Add("廣州");
this.ddlCity.Items.Add("佛山");
this.ddlCity.Items.Add("深圳");
this.ddlCity.Items.Add("珠海");
break;
case "河南":
this.ddlCity.Items.Clear();
this.ddlCity.Items.Add("鄭州");
this.ddlCity.Items.Add("新鄉(xiāng)");
this.ddlCity.Items.Add("安陽(yáng)");
this.ddlCity.Items.Add("信陽(yáng)");
break;
}
}
}
JavaScript無(wú)刷新聯(lián)動(dòng)
前臺(tái)頁(yè)面代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="jacascript_Default" %>
<!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 id="Head1" runat="server">
<title>無(wú)標(biāo)題頁(yè)</title>
<script type="text/javascript">
function FillData(strcity) {
document.getElementById("ddlCity").options.length = 0;
var indexofcity;
var city;
while (strcity.length > 0) {
indexofcity = strcity.indexOf(",");
if (indexofcity > 0) {
city = strcity.substring(0, indexofcity);
strcity = strcity.substring(indexofcity + 1);
document.getElementById("ddlCity").add(new Option(city, city));
}
else {
document.getElementById("ddlCity").add(new Option(strcity, strcity));
break;
}
}
}
</script>
</head>
<body>
<form id="form2" runat="server">
<div>
<table width="700px" border="1" cellpadding="5" cellspacing="0">
<tr>
<td colspan="2" align="center">
腳本方法實(shí)現(xiàn)刷新
</td>
</tr>
<tr>
<td>
選擇省份:
</td>
<td>
<select id="ddlPro" style="width: 201px">
<option value="湖北">湖北</option>
<option value="河北">河北</option>
<option value="廣東">廣東</option>
<option value="河南">河南</option>
</select>
<input id="btnQuery" type="button" value=" 查詢" onclick="City()" />
</td>
</tr>
<tr>
<td>
城市:
</td>
<td>
<asp:DropDownList ID="ddlCity" runat="server" Width="201px">
</asp:DropDownList>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
后臺(tái)代碼:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
public partial class jacascript_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder myscript = new StringBuilder();
myscript.Append("function City() {\n");
myscript.Append("var ddlpro=document.getElementById('ddlPro');\n");
myscript.Append("var pro=ddlpro.options[ddlpro.selectedIndex].innerText;\n");
//myscript.Append("var pro=document.getElementById('txtPro').value;\n");
myscript.Append("switch(pro) { \n");
myscript.Append("case '湖北':\n");
myscript.Append("FillData('" + GetCityStr("湖北") + "');\n");
myscript.Append("break;\n");
myscript.Append("case '河北':\n");
myscript.Append("FillData('" + GetCityStr("河北") + "');\n");
myscript.Append("break;\n");
myscript.Append("case '廣東':\n");
myscript.Append("FillData('" + GetCityStr("廣東") + "');\n");
myscript.Append("break;\n");
myscript.Append("case '河南':\n");
myscript.Append("FillData('" + GetCityStr("河南") + "');\n");
myscript.Append("break;}\n");
myscript.Append("}\n");
Page.ClientScript.RegisterClientScriptBlock(typeof(string), "city", myscript.ToString(), true);
}
private string GetCityStr(string pro)
{
string city = "";
switch (pro)
{
case "湖北":
city = "武漢,黃岡,黃石,襄樊";
break;
case "河北":
city = "石家莊,唐山,承德,邯鄲";
break;
case "廣東":
city = "廣州,佛山,深圳,珠海";
break;
case "河南":
city = "鄭州,新鄉(xiāng),安陽(yáng),信陽(yáng)";
break;
}
return city;
}
}
CallBack無(wú)刷新聯(lián)動(dòng)
前臺(tái)代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="callback_Default" %>
<!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 id="Head1" runat="server">
<title>無(wú)標(biāo)題頁(yè)</title>
<script type="text/javascript">
function FillData()
{
var ddlpro=document.getElementById('ddlPro');
var pro=ddlpro.options[ddlpro.selectedIndex].value;
<% =ClientScript.GetCallbackEventReference(this,"pro","FillDll",null) %>
}
function FillDll(strcity)
{
document.getElementById("ddlCity").options.length=0;
var indexofcity;
var city;
while(strcity.length>0)
{
indexofcity=strcity.indexOf(",");
if(indexofcity>0)
{
city=strcity.substring(0,indexofcity);
strcity=strcity.substring(indexofcity+1);
document.getElementById("ddlCity").add(new Option(city,city));
}
else
{
document.getElementById("ddlCity").add(new Option(strcity,strcity));
break;
}
}
}
</script>
</head>
<body>
<form id="form2" runat="server">
<div>
<table width="700px" border="1" cellpadding="5" cellspacing="0">
<tr>
<td colspan="2" align="center">
callback方法實(shí)現(xiàn)刷新
</td>
</tr>
<tr>
<td>
選擇省份:
</td>
<td>
<select id="ddlPro" style="width: 200px">
<option value="湖北">湖北</option>
<option value="河北">河北</option>
<option value="廣東">廣東</option>
<option value="河南">河南</option>
</select>
<input id="btnQuery" type="button" value=" 查詢" onclick="FillData()" />
</td>
</tr>
<tr>
<td>
城市:
</td>
<td>
<asp:DropDownList ID="ddlCity" runat="server" Width="201px">
</asp:DropDownList>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
后臺(tái)代碼:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class callback_Default : System.Web.UI.Page,ICallbackEventHandler
{
private string _data;
protected void Page_Load(object sender, EventArgs e)
{
}
ICallbackEventHandler 成員
}
Ajax無(wú)刷新聯(lián)動(dòng)
該例子也要用到兩個(gè)頁(yè)面:oec203index.aspx和datapage.aspx. datapage.aspx主要用來(lái)回送要顯示的數(shù)據(jù)
.aspx頁(yè)面前臺(tái)代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="ajax_Default" %>
<!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 id="Head1" runat="server">
<title>無(wú)標(biāo)題頁(yè)</title>
<script type="text/javascript">
var xmlhttp;
function getData() {
var ddlpro = document.getElementById("ddlPro");
var pro = ddlpro.options[ddlpro.selectedIndex].innerText;
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange = statechange;
xmlhttp.Open("GET", "datapage.aspx?pro=" + pro, true);
xmlhttp.Send();
}
function statechange() {
if (xmlhttp.readystate == 4) {
if (xmlhttp.status == 200) {
FillData(xmlhttp.responseText);
}
}
}
function FillData(strcity) {
document.getElementById("ddlCity").options.length = 0;
var indexofcity;
var city;
while (strcity.length > 0) {
indexofcity = strcity.indexOf(",");
if (indexofcity > 0) {
city = strcity.substring(0, indexofcity);
strcity = strcity.substring(indexofcity + 1);
document.getElementById("ddlCity").add(new Option(city, city));
}
else {
document.getElementById("ddlCity").add(new Option(strcity, strcity));
break;
}
}
}
</script>
</head>
<body>
<form id="form2" runat="server">
<div>
<table width="700px" border="1" cellpadding="5" cellspacing="0">
<tr>
<td colspan="2" align="center">
ajax方法實(shí)現(xiàn)刷新
</td>
</tr>
<tr>
<td>
選擇省份:
</td>
<td>
<select id="ddlPro" style="width: 201px">
<option value="湖北">湖北</option>
<option value="河北">河北</option>
<option value="廣東">廣東</option>
<option value="河南">河南</option>
</select>
<input id="btnQuery" type="button" value=" 查詢" onclick="getData()" />
</td>
</tr>
<tr>
<td>
城市:
</td>
<td>
<asp:DropDownList ID="ddlCity" runat="server" Width="201px">
</asp:DropDownList>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
datapage.aspx后臺(tái)代碼:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class ajax_datapage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string pro = Request.QueryString["pro"];
Response.Clear();
switch (pro)
{
case "湖北":
Response.Write("武漢,黃岡,黃石,襄樊");
break;
case "河北":
Response.Write("石家莊,唐山,承德,邯鄲");
break;
case "廣東":
Response.Write("廣州,佛山,深圳,珠海");
break;
case "河南":
Response.Write("鄭州,新鄉(xiāng),安陽(yáng),信陽(yáng)");
break;
}
}
}
以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。
- 落伍首發(fā) php+mysql 采用ajax技術(shù)的 省 市 地 3級(jí)聯(lián)動(dòng)無(wú)刷新菜單 源碼
- Ajax實(shí)現(xiàn)無(wú)刷新三聯(lián)動(dòng)下拉框
- 適用與firefox ASP.NET無(wú)刷新二級(jí)聯(lián)動(dòng)下拉列表
- Jquery實(shí)現(xiàn)無(wú)刷新DropDownList聯(lián)動(dòng)實(shí)現(xiàn)代碼
- 用Jquery實(shí)現(xiàn)多級(jí)下拉框無(wú)刷新的聯(lián)動(dòng)
- ajax.net +jquery 無(wú)刷新三級(jí)聯(lián)動(dòng)的實(shí)例代碼
- jQuery JSON實(shí)現(xiàn)無(wú)刷新三級(jí)聯(lián)動(dòng)實(shí)例探討
- jquery ajax實(shí)現(xiàn)下拉框三級(jí)無(wú)刷新聯(lián)動(dòng),且保存保持選中值狀態(tài)
相關(guān)文章
js cookies實(shí)現(xiàn)簡(jiǎn)單統(tǒng)計(jì)訪問(wèn)次數(shù)
js cookies實(shí)現(xiàn)簡(jiǎn)單統(tǒng)計(jì)訪問(wèn)次數(shù)的實(shí)現(xiàn)代碼。主要是掌握js對(duì)cookies的操作。2009-11-11
TypeScript裝飾器之項(xiàng)目數(shù)據(jù)轉(zhuǎn)換詳解
這篇文章主要為大家詳細(xì)介紹了TypeScript項(xiàng)目中是如何進(jìn)行數(shù)據(jù)轉(zhuǎn)換的,文中的示例代碼簡(jiǎn)潔易懂,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-10-10
基于js實(shí)現(xiàn)微信發(fā)送好友如何分享到朋友圈、微博
微信瀏覽器內(nèi)置了javascript私有對(duì)象WeixinJSBridge,可以實(shí)現(xiàn)發(fā)送給朋友、分享到朋友圈、分享到微博等功能,本篇文章給大家介紹基于js實(shí)現(xiàn)微信發(fā)送給朋友如何分享到朋友圈、微博,感興趣的朋友一起學(xué)習(xí)吧2015-11-11
打造通用的勻速運(yùn)動(dòng)框架(實(shí)例講解)
下面小編就為大家?guī)?lái)一篇打造通用的勻速運(yùn)動(dòng)框架(實(shí)例講解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10
微信 jssdk 簽名錯(cuò)誤invalid signature的解決方法
這篇文章主要介紹了微信 jssdk 簽名錯(cuò)誤invalid signature的解決方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-01-01
用js模擬JQuery的show與hide動(dòng)畫(huà)函數(shù)代碼
用javascript實(shí)現(xiàn)的模擬jquery下的顯示與隱藏的動(dòng)畫(huà)效果,學(xué)習(xí)的朋友可以參考下。2010-09-09
JS獲取隨機(jī)數(shù)和時(shí)間轉(zhuǎn)換的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇JS獲取隨機(jī)數(shù)和時(shí)間轉(zhuǎn)換的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-07-07
js實(shí)現(xiàn)九宮格圖片半透明漸顯特效的方法
這篇文章主要介紹了js實(shí)現(xiàn)九宮格圖片半透明漸顯特效的方法,涉及js操作css特效的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-02-02
JS實(shí)現(xiàn)的表格行上下移動(dòng)操作示例
這篇文章主要介紹了JS實(shí)現(xiàn)的表格行上下移動(dòng)操作,涉及javascript針對(duì)頁(yè)面元素節(jié)點(diǎn)與屬性的相關(guān)操作技巧,需要的朋友可以參考下2016-08-08
Array.prototype.slice.apply的使用方法
arguments在JavaScript語(yǔ)法中是函數(shù)特有的一個(gè)對(duì)象屬性(Arguments對(duì)象),用來(lái)引用調(diào)用該函數(shù)時(shí)傳遞的實(shí)際參數(shù)。2010-03-03

