技法71 (◐‿◑) 获得子窗口的返回值
本帖最后由 不二如是 于 2017-10-29 20:14 编辑http://xxx.fishc.com/forum/201705/05/225545py2j222x5z6x55n2.png
按照提示,完成代码,秀秀你的编程能力!
不许看答案,否则打屁屁
分析:
在70中介绍了如何打开一个模态窗口,那么打开窗口后,能不能搞一点交互呢?例如获得返回值。
如果能获得返回值,这个值可以帮助网站处理很多需求,例如有一位鱼油,想在弹窗中输入一些信息,为了方便用户查看修改后的信息,就要用到本次的主角。
Code:
父窗口HTML:
<h2>获取子窗口的返回值</h2>
<input id='opentChildWindowValue' type="button"value="打开模态窗口" />
子窗口HTML:
<title>人家是模态子窗口</title>
<input type="text" id='setReturnValue' value="填写返回值-传给隔壁大佬" name="btn">
<input type="button" value="发送返回值" name="btn" onclick="getReturnV(document.getElementById('setReturnValue').value)">
父窗口JS:
<script type="text/javascript">
window.onload = function(){
document.getElementById("opentChildWindowValue").onclick = function(){
var returnV = window.showModalDialog("child.html");//子窗口的引用
if(returnV){//监听子窗口返回值
alert("返回值为:" + returnV);
}
}
};
</script>
子窗口JS:
<script language="javascript">
//父窗体子模式窗口的简单模拟,为了简单、直观,将Javascript代码直接写入html页面中
function getReturnV(returnValue){
//window.returnValue 用于返回window.showModalDialog函数打开模式窗口的值
window.returnValue = returnValue;
window.close();
}
</script>
请按照自己的理解订正对概念的认知
代码说明(秀智商){:10_256:} :
**** Hidden Message *****
回顾:
技法70 (◐‿◑) 打开模态窗口
源代码:
○面试题索引贴●
如果喜欢,请订阅{:10_303:} :
HTML5 - 庖丁解牛 + JavaScript - 庖丁解牛
如果喜欢,别忘了评分{:10_281:} :
http://xxx.fishc.com/forum/201709/19/094516hku92k2g4kefz8ms.gif Merci. 有些浏览器不支持啊
看看答案 {:10_265:} 斑竹啊,内容过期了,上一节的showModalDialog都不行,这个肯定也不行了{:10_284:} emmm ??? {:5_102:} 1
页:
[1]