实现无刷新联动例子汇总

Iframe实现无刷新联动

iframe的无刷新其实是局部刷新,状态栏的滚动条还是会滚动,只是页面不会闪烁,这是一种比较老的技术了,在处理的数据两大的时候会比较慢,在本例中需要两个页面:index.aspx和frame.asapx,index.aspx用来显示界面,其中有一个iframe标记,指向frame.aspx页用来显示结果
index.aspx前台代码

<%@ 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 runat="server"> <title>无标题页</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 runat="server"> <div> <table cellpadding="3" cellspacing="0"> <tr> <td colspan="2"> Iframe实现局部刷新 </td> </tr> <tr> <td> 省份名称: </td> <td> <select> <option value="湖北">湖北</option> <option value="河北">河北</option> <option value="广东">广东</option> <option value="河南">河南</option> </select> <input type="button" value="查询" /> </td> </tr> <tr> <td> 显示城市列表 </td> <td> <iframe src="https://www.jb51.net/frame.aspx" frameborder="0" scrolling="no" /> </td> </tr> </table> </div> </form> </body> </html>

frame.aspx的前台代码:

<%@ 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 runat="server"> <title>无标题页</title> </head> <body> <form runat="server"> <div> <asp:DropDownList runat="server"> </asp:DropDownList> </div> </form> </body> </html>

frame.aspx后台代码:

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("新乡"); this.ddlCity.Items.Add("安阳"); this.ddlCity.Items.Add("信阳"); break; } } }

JavaScript无刷新联动

前台页面代码:

<%@ 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 runat="server"> <title>无标题页</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 runat="server"> <div> <table cellpadding="5" cellspacing="0"> <tr> <td colspan="2"> 脚本方法实现刷新 </td> </tr> <tr> <td> 选择省份: </td> <td> <select> <option value="湖北">湖北</option> <option value="河北">河北</option> <option value="广东">广东</option> <option value="河南">河南</option> </select> <input type="button" value=" 查询" /> </td> </tr> <tr> <td> 城市: </td> <td> <asp:DropDownList runat="server"> </asp:DropDownList> </td> </tr> </table> </div> </form> </body> </html>

后台代码:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgjwws.html