欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Javascript showModalDialog兩個(gè)窗體之間傳值

 更新時(shí)間:2009年09月25日 14:51:35   作者:  
前一篇文章Javascript怎么在兩個(gè)窗體之間傳值中講到了如何利用window.open()方法打開(kāi)新窗體,并在兩個(gè)窗體之間傳值的方法。
Javascript 兩個(gè)窗體之間傳值實(shí)現(xiàn)代碼
javascript中還有一個(gè)函數(shù)window.showModalDialog也可以打開(kāi)一個(gè)新窗體,不過(guò)他打開(kāi)的是一個(gè)模態(tài)窗口,那么如何在父窗體和子窗體之間傳值呢?我們先看該函數(shù)的定義:vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])
參數(shù)說(shuō)明:
sURL--必選參數(shù),類(lèi)型:字符串。用來(lái)指定對(duì)話框要顯示的文檔的URL。
vArguments--可選參數(shù),類(lèi)型:變體。用來(lái)向?qū)υ捒騻鬟f參數(shù)。傳遞的參數(shù)類(lèi)型不限,包括數(shù)組等。對(duì)話框通過(guò)window.dialogArguments來(lái)取得傳遞進(jìn)來(lái)的參數(shù)。
sFeatures--可選參數(shù),類(lèi)型:字符串。用來(lái)描述對(duì)話框的外觀等信息,可以使用以下的一個(gè)或幾個(gè),用分號(hào)“;”隔開(kāi)。
dialogHeight :對(duì)話框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默認(rèn)的單位是em,而IE5中是px,為方便其見(jiàn),在定義modal方式的對(duì)話框時(shí),用px做單位。
dialogWidth: 對(duì)話框?qū)挾取?
dialogLeft: 離屏幕左的距離。
dialogTop: 離屏幕上的距離。
center: {yes | no | 1 | 0 }:窗口是否居中,默認(rèn)yes,但仍可以指定高度和寬度。
help: {yes | no | 1 | 0 }:是否顯示幫助按鈕,默認(rèn)yes。
resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改變大小。默認(rèn)no。
status: {yes | no | 1 | 0 } [IE5+]:是否顯示狀態(tài)欄。默認(rèn)為yes[ Modeless]或no[Modal]。
scroll:{ yes | no | 1 | 0 | on | off }:指明對(duì)話框是否顯示滾動(dòng)條。默認(rèn)為yes。
如:"dialogWidth=200px;dialogHeight=100px"
因此我們可以通過(guò)window.dialogArguments參數(shù)來(lái)在兩個(gè)窗體之間傳值
如下面兩個(gè)頁(yè)面:FatherPage.htm:
復(fù)制代碼 代碼如下:

<script type="text/javascript">
function OpenChildWindow()
{
window.showModalDialog('ChildPage.htm',document.getElementById('txtInput').value);
}
</script>
<input type="text" id="txtInput" />
<input type="button" value="OpenChild" onclick="OpenChildWindow()" />

ChildPage.htm:
復(fù)制代碼 代碼如下:

<body onload="Load()">
<script type="text/javascript">
function Load()
{
document.getElementById('txtInput').value=window.dialogArguments ;
}
</script>
<input type="text" id="txtInput" />
</body>

上面只是傳遞簡(jiǎn)單的字符串,我們還可以傳遞數(shù)組,如:FatherPage.htm:
XML-Code:
復(fù)制代碼 代碼如下:

<script type="text/javascript">
function OpenChildWindow()
{
var args = new Array();
args[0] = document.getElementById('txtInput').value;
window.showModalDialog('ChildPage.htm',args);
}
</script>
<input type="text" id="txtInput" />
<input type="button" value="OpenChild" onclick="OpenChildWindow()" />ChildPage.htm:
XML-Code:
<script type="text/javascript">
function Load()
{
document.getElementById('txtInput').value=window.dialogArguments[0] ;
}
</script>

同樣我們還可以傳遞對(duì)象,如:FatherPage.htm:
XML-Code:
復(fù)制代碼 代碼如下:

<script type="text/javascript">
function OpenChildWindow()
{
var obj = new Object();
obj.name = document.getElementById('txtInput').value;
window.showModalDialog('ChildPage.htm',obj);
}
</script>
<input type="text" id="txtInput" />
<input type="button" value="OpenChild" onclick="OpenChildWindow()" />

ChildPage.html:
XML-Code:
復(fù)制代碼 代碼如下:

<script type="text/javascript">
function Load()
{
var obj = window.dialogArguments;
document.getElementById('txtInput').value=obj.name ;
}
</script>

以上都是從父窗體向子窗體傳值,那么如何從子窗體向父窗體傳值呢 ?其實(shí)通過(guò)window.returnValue就可以獲取子窗體的值,window.returnValue與window.dialogArguments一樣,可以是任意變量,包括字符串,數(shù)組,對(duì)象等。如:FatherPage.html:
XML-Code:
復(fù)制代碼 代碼如下:

<script type="text/javascript">
function OpenChildWindow()
{
var obj = new Object();
obj.name = document.getElementById('txtInput').value;
var result = window.showModalDialog('ChildPage.htm',obj);
document.getElementById('txtInput').value = result.name;
}
</script>
<input type="text" id="txtInput" />
<input type="button" value="OpenChild" onclick="OpenChildWindow()" />

ChildPage.html:
XML-Code:
復(fù)制代碼 代碼如下:

<body onload="Load()">
<script type="text/javascript">
function Load()
{
var obj = window.dialogArguments;
document.getElementById('txtInput').value=obj.name ;
}
function SetValue()
{
var obj = new Object();
obj.name = document.getElementById('txtInput').value;
window.returnValue = obj;
window.close();
}
</script>
<input type="text" id="txtInput" />
<input type="button" value="SetFather" onclick="SetValue()" />
</body>

相關(guān)文章

最新評(píng)論