亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

靜態(tài)頁(yè)面的值傳遞(三部曲)

 更新時(shí)間:2006年09月25日 00:00:00   作者:  
這兩窗口之間存在著關(guān)系.父窗口parent.htm打開(kāi)子窗口son.htm
子窗口可以通過(guò)window.opener指向父窗口.這樣可以訪問(wèn)父窗口的對(duì)象.

優(yōu)點(diǎn):取值方便.只要window.opener指向父窗口,就可以訪問(wèn)所有對(duì)象.
       不僅可以訪問(wèn)值,還可以訪問(wèn)父窗口的方法.值長(zhǎng)度無(wú)限制.
缺點(diǎn):兩窗口要存在著關(guān)系.就是利用window.open打開(kāi)的窗口.不能跨域.


Post.htm

<input type=text name=maintext>
<input type=button onclick="window.open('Read.htm')" value="Open">

Read.htm

<script language="javascript" >
//window.open打開(kāi)的窗口.
//利用opener指向父窗口.
var parentText = window.opener.document.all.maintext.value;
alert(parentText);
</script>


利用Cookie.

Cookie是瀏覽器存儲(chǔ)少量命名數(shù)據(jù).
它與某個(gè)特定的網(wǎng)頁(yè)或網(wǎng)站關(guān)聯(lián)在一起.
Cookie用來(lái)給瀏覽器提供內(nèi)存,
以便腳本和服務(wù)器程序可以在一個(gè)頁(yè)面中使用另一個(gè)頁(yè)面的輸入數(shù)據(jù).

優(yōu)點(diǎn):可以在同源內(nèi)的任意網(wǎng)頁(yè)內(nèi)訪問(wèn).生命期可以設(shè)置.
缺點(diǎn):值長(zhǎng)度有限制.

Post.htm

<input type="text" name="txt1">
<input type="button" onclick="setCookie('baobao',document.all.txt1.value)" value="Post">
<script language="javascript" >
function setCookie(name,value)
{
/*
 *--------------- setCookie(name,value) -----------------
 * setCookie(name,value) 
 * 功能:設(shè)置得變量name的值
 * 參數(shù):name,字符串;value,字符串.
 * 實(shí)例:setCookie('username','baobao')
 *--------------- setCookie(name,value) -----------------
 */
    var Days = 30; //此 cookie 將被保存 30 天
    var exp  = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
    location.href = "Read.htm"; //接收頁(yè)面.
}
</script>


Read.htm

<script language="javascript" >
function getCookie(name)
{
/*
 *--------------- getCookie(name) -----------------
 * getCookie(name)
 * 功能:取得變量name的值
 * 參數(shù):name,字符串.
 * 實(shí)例:alert(getCookie("baobao"));
 *--------------- getCookie(name) -----------------
 */
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr !=null) return unescape(arr[2]); return null;
}
alert(getCookie("baobao"));
</script>


 URL篇

能過(guò)URL進(jìn)行傳值.把要傳遞的信息接在URL上.

優(yōu)點(diǎn):取值方便.可以跨域.
缺點(diǎn):值長(zhǎng)度有限制.

Post.htm

<input type="text" name="username">
<input type="text" name="sex">
<input type="button" onclick="Post()" value="Post">
<script language="javascript" >
function Post()
{
    //單個(gè)值 Read.htm?username=baobao;
    //多全值 Read.htm?username=baobao&sex=male;
    url = "Read.htm?username="+escape(document.all.username.value);
    url += "&sex=" + escape(document.all.sex.value);
    location.href=url;
}
</script>


Read.htm

<script language="javascript" >
/*
 *--------------- Read.htm -----------------
 * Request[key]
 * 功能:實(shí)現(xiàn)ASP的取得URL字符串,Request("AAA")
 * 參數(shù):key,字符串.
 * 實(shí)例:alert(Request["AAA"])
 *--------------- Request.htm -----------------
 */
var url=location.search;
var Request = new Object();
if(url.indexOf("?")!=-1)
{
    var str = url.substr(1)  //去掉?號(hào)
    strs = str.split("&");
    for(var i=0;i<strs.length;i++)
    {
        Request[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
    }
}
alert(Request["username"])
alert(Request["sex"])
</script>

相關(guān)文章

最新評(píng)論