日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

网页间的传值

發(fā)布時間:2024/4/11 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 网页间的传值 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
網頁間的傳值有三種方法,一是通過地址欄;二是通過cookie;三是直接調用處理,即通過window.opener獲取具體的參數(shù);這種方法比較靈活。
  父頁面:
<html>
<head><title>網頁間的參數(shù)傳遞[父網頁]</title>
<script language="javascript">
??? function test1(){
??????? window.open('child.html','popup',200,300)
??? } function test2(){
??????? SetCookie('參數(shù)1',document.all.參數(shù)1.value,123);
??????? SetCookie('參數(shù)2',document.all.參數(shù)2.value,123);
??????? window.open('child.html','popup',200,300)
??? } function SetCookie(Para,Value,Expiredays){
??????? var Exdate=new Date()
??????? Exdate.setDate(Exdate.getDate()+Expiredays)
??????? document.cookie=Para+ "=" +escape(Value)+((Expiredays==null) ? "" : ";expires="+Exdate.toGMTString())
??? } function test3(){
??????? var Url="child.html?參數(shù)1="+escape(document.all.參數(shù)1.value);
??????? Url+="&參數(shù)2="+escape(document.all.參數(shù)2.value)
??????? window.open(Url,'popup',200,300)
??? }
</script>
</head>
<body>
<div id=PSP style="width:300;height:300;top=50;left=50;">
參數(shù)1:<input type="text" name="參數(shù)1" /></br>
參數(shù)2:<input type="text" name="參數(shù)2" /></br>
<input type="button" value="傳值" οnclick="test1();"/>
<input type="button" value="Cookie傳值" οnclick="test2()"/>
<input type="button" value="地址欄傳值" οnclick="test3()"/>
</div>
</body>
</html>
  子頁面:
<html>
<head><title>網頁間的傳值[子網頁]</title>
</head>
<script languang="javascript">
??? function ViewInfo1() {
??????? var ParentW = window.opener;
??????? info="參數(shù)1:"+ParentW.document.all.參數(shù)1.value;
??????? info+="??? 參數(shù)2:"+ParentW.document.all.參數(shù)2.value;
??????? ParentW.document.getElementById('參數(shù)1').style.backgroundColor = "red";//更改背景色
??????? alert(info);
??? } function GetCookie(Para){
??????? if (document.cookie.length>0){
??????????? c_start=document.cookie.indexOf(Para + "=");
??????????? if (c_start!=-1){
??????????????? c_start=c_start + Para.length+1 ;
??????????????? c_end=document.cookie.indexOf(";",c_start);
??????????????? if (c_end==-1) c_end=document.cookie.length;
??????????????? return unescape(document.cookie.substring(c_start,c_end));
??????????? }
??????? }
??? }
???
??? function ViewInfo2(){
??????? var Para1=GetCookie('參數(shù)1');
??????? var Para2=GetCookie('參數(shù)2');
??????? var info="參數(shù)1:"+Para1+"??? 參數(shù)2:"+Para2;
??????? alert(info);
??? } function ViewInfo3(){
??????? var Url=location.search;
??????? var ParaName=new Array();
??????? var ParaValue=new Array();
??????? var info='';
??????? if(Url.indexOf("?")!=-1){
??????????? var S1 = Url.substr(1);
??????????? var SSS = S1.split("&");
??????????? for(var i=0;i<SSS.length;i++){
??????????????? ParaName[i]=SSS[i].split("=")[0];
??????????????? ParaValue[i]=SSS[i].split("=")[1];
??????????? }
??????? }
??????? for(var i=0;i<ParaName.length;i++){
??????????? if(info==''){info=ParaName[i]+"="+ParaValue[i];}
??????????? else {
??????????? info+="??? "+ParaName[i]+"="+ParaValue[i];}
??????? }
??????? alert(info) ; }
</script>
<body>
<input type="button" value="直接獲取參數(shù)" οnclick="ViewInfo1();"/>
<input type="button" value="cookie傳參數(shù)" οnclick="ViewInfo2();"/>
<input type="button" value="地址欄傳參數(shù)" οnclick="ViewInfo3();"/>
</body>
</html>

總結

以上是生活随笔為你收集整理的网页间的传值的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。