Flask接口签名sign原理与实例代码浅析
225
2023-08-02
实现无刷新联动例子汇总
Iframe实现无刷新联动
iframe的无刷新其实是局部刷新,状态栏的滚动条还是会滚动,只是页面不会闪烁,这是一种比较老的技术了,在处理的数据两大的时候会比较慢,在本例中需要两个页面:index.aspx和frame.asapx,index.aspx用来显示界面,其中有一个iframe标记,指向frame.aspx页用来显示结果
index.aspx前台代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="_Default" %>
function Query() {
var ddlpro = document.getElementById('ddlPro');
var pro = ddlpro.options[ddlpro.selectedIndex].innerText;
if (pro != "") {
document.getElementById("iframe1").src = "frame.aspx?Pro=" + pro;
}
}
Iframe实现局部刷新
省份名称:
显示城市列表
height="100%" frameborder="0" scrolling="no" />
frame.aspx的前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="frame.aspx.cs" Inherits="myframe" %>
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" %>
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;
}
}
}
脚本方法实现刷新
选择省份:
城市:
后台代码:
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 = "郑州,新乡,安阳,信阳";
break;
}
return city;
}
}
CallBack无刷新联动
前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="callback_Default" %>
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;
}
}
}
callback方法实现刷新
选择省份:
城市:
后台代码:
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无刷新联动
该例子也要用到两个页面:oec203index.aspx和datapage.aspx. datapage.aspx主要用来回送要显示的数据
.aspx页面前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="ajax_Default" %>
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;
}
}
}
ajax方法实现刷新
选择省份:
<http://;/td>
城市:
datapage.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 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("郑州,新乡,安阳,信阳");
break;
}
}
}
以上所述就是本文的全部内容了,希望大家能够喜欢。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~