马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 不二如是 于 2017-10-29 20:14 编辑
按照提示,完成代码,秀秀你的编程能力!
不许看答案,否则打屁屁
分析:
在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>
请按照自己的理解订正对概念的认知
代码说明(秀智商) :
回顾:
源代码:
71.zip
(1.22 KB, 下载次数: 7, 售价: 5 鱼币)
如果喜欢,请订阅 :
如果喜欢,别忘了评分 :
|