當(dāng)前位置:軟件學(xué)堂 > 資訊首頁(yè) > 網(wǎng)絡(luò)編程 > 編程其他 > JS代碼實(shí)現(xiàn)在打開的窗口中返回?cái)?shù)據(jù)

JS代碼實(shí)現(xiàn)在打開的窗口中返回?cái)?shù)據(jù)

2012/11/3 08:16:20作者:佚名來源:網(wǎng)絡(luò)

移動(dòng)端

【實(shí)例名稱】

JS代碼實(shí)現(xiàn)在打開的窗口中返回?cái)?shù)據(jù)

【實(shí)例描述】

當(dāng)打開窗口后,客戶端已經(jīng)與服務(wù)器端失去了聯(lián)系。那么如何從新窗口返回一個(gè)計(jì)算結(jié)果給父窗口呢?本例學(xué)習(xí)如何從打開的窗口中返回?cái)?shù)據(jù)。

【實(shí)例代碼】

父窗體的代碼如下所示:

<HTML>   
<head>
<title>無標(biāo)題-學(xué)無憂(www.denvermotorcycleaccidentlawyer.com)</title>
</head>
<BODY>   
<body> 
<script language="javascript"> 
            //打開模式窗口
str =window.showModalDialog("12.11  從打開的窗口中返回?cái)?shù)據(jù)1.htm",
"dialogWidth=200px;dialogHeight=100px");
alert(str);//輸出返回值
 </script>
</body>
</HTML>

模式窗口中的代碼如下所示:

<!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>     <title>無標(biāo)題頁(yè)-學(xué)無憂(www.denvermotorcycleaccidentlawyer.com)</title>     <script language=javascript>     window.returnValue="測(cè)試的返回?cái)?shù)據(jù)";     </script> </head> <body> </body> </html>

【運(yùn)行效果】

 在打開的窗口中返回?cái)?shù)據(jù)運(yùn)行效果

【難點(diǎn)剖析】

本例的難點(diǎn)是如何捕獲新窗口的返回值。首先使用“showModalDialog”方法打開新窗口,中使用“str”變量獲取返回值。在模式窗口中,使用“retumValue”返回當(dāng)前窗體中的數(shù)據(jù)。

【源碼下載】

為了JS代碼的準(zhǔn)確性,請(qǐng)點(diǎn)擊:在打開的窗口中返回?cái)?shù)據(jù) 進(jìn)行本實(shí)例源碼下載 

標(biāo)簽: JS代碼  窗口  數(shù)據(jù)