當(dāng)前位置:軟件學(xué)堂 > 資訊首頁(yè) > 網(wǎng)絡(luò)編程 > 編程其他 > 獲取模式窗口的值JS代碼怎么寫

獲取模式窗口的值JS代碼怎么寫

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

移動(dòng)端

【實(shí)例名稱】

獲取模式窗口的值JS代碼怎么寫

【實(shí)例描述】

在一些財(cái)務(wù)表格中,由于列數(shù)特別多,有時(shí)候需要用戶打開新的窗口輸入數(shù)據(jù)。本例學(xué)習(xí)如何實(shí)現(xiàn)在新的窗口中輸人數(shù)據(jù),并返回給父窗口的功能。

【實(shí)例代碼】

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>無標(biāo)題頁(yè)-學(xué)無憂(www.denvermotorcycleaccidentlawyer.com)</title>
<script language="javascript">
function openwin()
{
    var url="12.23  獲取模式窗口的值1.htm";
    //打開模式窗口,注意模式窗口的樣式
    var mydata=showModalDialog(url,null,
"dialogWidth:300px;dialogHeight:120px;
center:yes;help:No;status:no;resizable:Yes;edge:sunken");
    if(mydata)
     alert("您輸入的值為:" +mydata.value);
}
</script>
</head>
<body>
    <input id="Button1" type="button" 
value="打開窗口" onclick="openwin()" />
</body>
</html>
設(shè)計(jì)模式窗口“獲取模式窗口的值|.htm”的代碼如下所示:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>標(biāo)題頁(yè)-學(xué)無憂(www.denvermotorcycleaccidentlawyer.com)</title>
<script language=javascript>
 function ReturnWin()
 {
     var returnData=new Object();     
//創(chuàng)建變量
    returnData.value=document.getElementById("Text1").value;
        //設(shè)置變量的值
    window.returnValue=returnData;   
//窗體返回?cái)?shù)據(jù)
    window.close();                 
 //關(guān)閉窗口
 }
</script>
</head>
<body>
    <input id="Text1" type="text" />
<input id="Button1" type="button" value="返回" onclick="ReturnWin()" />
</body>
</html>

【運(yùn)行效果】

 獲取模式窗口的值運(yùn)行效果

【難點(diǎn)剖析】

本例的重點(diǎn)是如何打開模式窗口?!皐indow.open”用來打開窗口,但用戶可以不操作此窗口,而繼續(xù)其他的操作:“showModalDialog”用來打開模式窗口,如果用戶不關(guān)閉此窗口,則不能執(zhí)行其他操作。

【源碼下載】

為了JS代碼的準(zhǔn)確性,請(qǐng)點(diǎn)擊:獲取模式窗口的值 進(jìn)行本實(shí)例源碼下載