下面代码可以.
A页:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="A.aspx.cs" Inherits="page_A" %>
<!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>
<style type="text/css">
.hidden
{
display:none;
}
.show
{
display:block;
}
</style>
<script type="text/javascript">
window.onload = function () {
document.getElementById("btn_a").attachEvent("onclick", function () {
document.getElementById("btn_a").className = "hidden";
document.getElementById("btn_b").className = "show";
});
document.getElementById("btn_b").attachEvent("onclick", function () {
document.getElementById("btn_b").className = "hidden";
document.getElementById("btn_a").className = "show";
});
document.getElementById("btn_b").attachEvent("onclick", function () {
document.getElementById("hyperLint_b").click();
});
if (document.referrer == "http://localhost/hymdclgl2010/page/B.aspx") {
document.getElementById("btn_a").click();
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" value="Button A" id="btn_a" class="show"/>
<input type="button" value="Button B" id="btn_b" class="hidden"/>
<a href="B.aspx" id="hyperLint_b" class="hidden">BBBB</a>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="B.aspx.cs" Inherits="page_B" %>
<!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">
window.attachEvent("onload", function () {
document.getElementById("btn").attachEvent("onclick", function () {
var hyperlink = document.createElement("a");
hyperlink.href = document.referrer;
document.body.appendChild(hyperlink);
hyperlink.click();
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
This is PageB
</div>
<input type="button" value="Back" id="btn" />
</form>
</body>
</html>
这是 ajax 的弊端, 你要想实现你说的功能,只有在URL 后面加上参数,初始化的时候再做判断。
用数组缓存已加载的数据,然后遍历这个数组