JS中showModalDialog 的使用解析
基本介紹:
window.showModalDialog() 方法用來(lái)創(chuàng)建一個(gè)顯示HTML內(nèi)容的模態(tài)對(duì)話框。(就是打開后不能操作父窗口,只能等模式 窗口關(guān)閉時(shí)才能操作)
window.showModelessDialog() 方法用來(lái)創(chuàng)建一個(gè)顯示HTML內(nèi)容的非模態(tài)對(duì)話框。(就是打開后仍然可以進(jìn)行其他的操作)
使用方法:
vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])
vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures])
參數(shù)說(shuō)明:
sURL -- 必選參數(shù),類型:字符串。用來(lái)指定對(duì)話框要顯示的文檔的URL。
vArguments -- 可選參數(shù),類型:變體。用來(lái)向?qū)υ捒騻鬟f參數(shù)。傳遞的參數(shù)類型不限,包括數(shù)組等。對(duì)話框通過(guò) window.dialogArguments來(lái)取得傳遞進(jìn)來(lái)的參數(shù)。
sFeatures -- 可選參數(shù),類型:字符串。用來(lái)描述對(duì)話框的外觀等信息,可以使用以下的一個(gè)或幾個(gè),用分號(hào)“;”隔開。
-------------------------------
參數(shù)傳遞:
1. 要想對(duì)話框傳遞參數(shù),是通過(guò)vArguments來(lái)進(jìn)行傳遞的。類型不限制,對(duì)于字符串類型,最大為4096個(gè)字符。也可以傳遞對(duì)象.
parent.html
<body>
用戶名:
<input id="usernameID" type="text" readonly/>
<input id="buttonID" type="button" value="選擇輸入" />
<script type="text/javascript">
var sURL = "showModalDialog2.html";
//將父窗口對(duì)象傳給子窗口
var vArguments = window;
var sFeatures = "dialogHeight:200px;dialogWidth:450px";
document.getElementById("buttonID").onclick = function(){
//單擊"選擇輸入"按鈕,彈出對(duì)話框以供選擇輸入
window.showModalDialog(sURL,vArguments,sFeatures);
}
</script>
</body>
children.html
<body>
<script type="text/javascript">
//單擊"選擇輸入"按鈕后,會(huì)將對(duì)應(yīng)的值顯示在父窗口文本框中
//接收父窗口傳過(guò)來(lái)的對(duì)象
var fatherWindow = window.dialogArguments;
function selectInput(inputElement){
//取得用戶名
var username = inputElement.parentNode.nextSibling.firstChild.nodeValue;
//將用戶名設(shè)置到父窗口相關(guān)的位置
fatherWindow.document.getElementById("usernameID").value = username;
}
</script>
<table border="1" align="center">
<tr>
<th>
操作
</th>
<th>
用戶名
</th>
</tr>
<tr>
<td>
<input type="button" value="選擇輸入" onclick="selectInput(this)" />
</td>
<td>
張三
</td>
</tr>
</table>
</body>
最終結(jié)果:
2.可以通過(guò)window.returnValue向打開對(duì)話框的窗口返回信息,可以是布爾值,整型值等以外還可以是個(gè)js數(shù)組,當(dāng)然也可以是對(duì)象.
parent.html
<script type="text/javascript">
/**
*通過(guò)controller轉(zhuǎn)向在模擬窗口加載JSP頁(yè)面
**/
function selectUserList(param) {
var sURL = "${pageContext.request.contextPath}/SelectUserController/selUser.do?checkTip="+param.checkType+"®Field="+param.regField";
var vArguments = window;
var sFeatures = "scrollbars=no;resizable=no;help=no;status=no;center:yes;dialogHeight=580px;dialogWidth=776px"";
return window.showModalDialog(sURL,vArguments,sFeatures);
}
/**
*通過(guò)JSON傳值,并返回JSON數(shù)組
**/
function getUser(){
var retValue = selectUserList({'checkType':'','regField':'more'});
</script>
- javascript showModalDialog模態(tài)對(duì)話框使用說(shuō)明
- js的window.showModalDialog及window.open用法實(shí)例分析
- Javascript showModalDialog兩個(gè)窗體之間傳值
- js showModalDialog參數(shù)的使用詳解
- javascript showModalDialog傳值與FireFox的window.open 父子窗口傳值示例
- js showModalDialog彈出窗口實(shí)例詳解
- javascript showModalDialog,open取得父窗口的方法
- JavaScript中window.showModalDialog()用法詳解
- javascript showModalDialog 多層模態(tài)窗口實(shí)現(xiàn)頁(yè)面提交及刷新的代碼
- JS對(duì)話框_JS模態(tài)對(duì)話框showModalDialog用法總結(jié)
- javascript showModalDialog 內(nèi)跳轉(zhuǎn)頁(yè)面的問(wèn)題
- js showModalDialog 彈出對(duì)話框的簡(jiǎn)單實(shí)例(子窗體)
- JS中showModalDialog關(guān)閉子窗口刷新主窗口用法詳解
相關(guān)文章
提交按鈕的name=''submit''引起的js失效問(wèn)題及原因
這篇文章主要介紹了提交按鈕的name='submit'引起的js失效問(wèn)題及原因,需要的朋友可以參考下2015-02-02javascript實(shí)現(xiàn)瀑布流動(dòng)態(tài)加載圖片原理
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)瀑布流動(dòng)態(tài)加載圖片原理,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08JavaScript實(shí)現(xiàn)斗地主游戲的思路
這篇文章主要介紹了JavaScript實(shí)現(xiàn)斗地主游戲的思路的相關(guān)資料,需要的朋友可以參考下2016-02-02JS圖片預(yù)加載 JS實(shí)現(xiàn)圖片預(yù)加載應(yīng)用
由于圖片加載慢,導(dǎo)致用戶體驗(yàn)特別差,本文將介紹一種圖片預(yù)加載技術(shù),需要了解的朋友可以參考下2012-12-12javascript實(shí)現(xiàn)復(fù)選框全選或反選
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)復(fù)選框全選或反選,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02