最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JavaScript 彈出子窗體并返回結(jié)果到父窗體的實(shí)現(xiàn)代碼

 更新時(shí)間:2016年05月28日 09:22:44   投稿:jingxian  
下面小編就為大家?guī)?lái)一篇JavaScript 彈出子窗體并返回結(jié)果到父窗體的實(shí)現(xiàn)代碼。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

思路:用window.showModalDialog方法獲取到彈出子窗體的引用,再在子頁(yè)面用window.returnValue="***"來(lái)返回結(jié)果。

示例代碼:(用jQuery簡(jiǎn)化實(shí)現(xiàn))

父頁(yè)面:parent.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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>父頁(yè)面</title>
<mce:script language="javascript"><!--
 
function showmodal()
{  
var strReturn = window.showModalDialog("son.html",null,"dialogWidth:800px;dialogHeight:600px;help:no;status:no"); 
var s="您選擇了:";
for(var i=0;i<strReturn.length;i++)
{
	s+=strReturn[i]+",";
	}
alert(s);

}
// --></mce:script>
</body>
</html>

子頁(yè)面 son.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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>子窗體</title>
<mce:script type="text/javascript" src="jquery-1.4.2.min.js" mce_src="jquery-1.4.2.min.js"></mce:script>
<mce:script type="text/javascript"><!--
var result;
$(function(){
		  $("#send").click(function(){
									 var result=new Array();
											$("[name=a]:checkbox:checked").each(function(){
												result.push($(this).val());									 
																						 });																	
									 window.returnValue=result;
									 window.close();
									 });
		  });
// --></mce:script>
</head>
<body>
<p>
<input type="checkbox" name="a" value="蘋(píng)果" />蘋(píng)果
<input type="checkbox" name="a" value="橘子" />橘子
<input type="checkbox" name="a" value="香蕉" />香蕉

<INPUT type="button" value="提交" id="send" /> 

</p>
</body>
</html>

總結(jié):

 參數(shù)傳遞:

1.   要想對(duì)話框傳遞參數(shù),是通過(guò)vArguments來(lái)進(jìn)行傳遞的。類(lèi)型不限制,對(duì)于字符串類(lèi)型,最大為4096個(gè)字符。也可以傳遞對(duì)象,例如:
-------------------------------

parent.htm

<script>
     var obj = new Object();
     obj.name="51js";
     window.showModalDialog("son.htm",obj,"dialogWidth=200px;dialogHeight=100px");
</script>

son.htm

<script>
     var obj = window.dialogArguments
     alert("您傳遞的參數(shù)為:" + obj.name)
</script>

2.   可以通過(guò)window.returnValue向打開(kāi)對(duì)話框的窗口返回信息,當(dāng)然也可以是對(duì)象。例如:

parent.htm

<script>
     str =window.showModalDialog("son.htm",,"dialogWidth=200px;dialogHeight=100px");
     alert(str);
</script>

son.htm

<script>
     window.returnValue="http://blog.csdn.net/a497785609";
</script> 

擴(kuò)展:

在.net中,可以通過(guò)這種方式來(lái)實(shí)現(xiàn)AJAX效果。當(dāng)子頁(yè)面?zhèn)鬟f所要選擇的參數(shù)后,父頁(yè)面可以實(shí)現(xiàn)ICallbackEventHandler接口,直接將獲取到的值傳回服務(wù)器端。或者用UpdatePanel的Load事件來(lái)?yè)渥降絺鬟f過(guò)來(lái)的參數(shù),從而繼續(xù)進(jìn)行服務(wù)器端處理。

以上這篇JavaScript 彈出子窗體并返回結(jié)果到父窗體的實(shí)現(xiàn)代碼就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

高淳县| 漳州市| 永春县| 民乐县| 鹤峰县| 郑州市| 高淳县| 右玉县| 凯里市| 泰安市| 密山市| 大厂| 临朐县| 肥乡县| 南澳县| 庆城县| 中牟县| 北碚区| 无极县| 柘荣县| 墨脱县| 普洱| 龙胜| 玛多县| 浑源县| 旅游| 武清区| 神池县| 宣化县| 潞城市| 大荔县| 罗江县| 井冈山市| 呼图壁县| 上饶市| 辉南县| 玛曲县| 资源县| 阿拉善左旗| 尼勒克县| 亚东县|