代码描述:js为showModalDialog()弹出窗口传值。js为showModalDialog()弹出窗口传值代码下载
大家知道使用window.showModalDialog()函数能够以弹窗的形式展现一个页面。 其实有时候并不是单纯的弹出这么一个页面,也可以为这个弹出页面传值,下面就做一下简单介绍。 代码实例: 主页面代码:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="https://www.51qianduan.com/" /> <title>51前端</title> <script type="text/javascript"> function OpenNew(){ var im=new valueAndMethod(); im.txtValue=document.getElementById("txtID").value; window.showModalDialog("B.html",im,""); } function valueAndMethod(){ this.txtValue="51前端"; this.Method=SetTxt; } function SetTxt(str){ document.getElementById("txtID").value=str; } window.onload=function(){ var obt=document.getElementById("bt"); obt.onclick=function(){ OpenNew(); } } </script> </head> <body> <form action="#"> <input id="txtID" type="text" value="输入内容" /><br /> <input type="button" id="bt" value="打开新的窗口"/> </form> </body> </html>
B.html页面代码:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="https://www.51qianduan.com/" /> <title>51前端</title> <script type="text/javascript"> var im; function Load(){ im=window.dialogArguments; if(im.txtValue=="输入内容"){ document.getElementById("txt").value="51前端一"; } else{ document.getElementById("txt").value=im.txtValue; } } function Set(){ im.Method(document.getElementById("txt").value); } window.onload=function(){ Load(); var obt=document.getElementById("bt"); obt.onclick=function(){ Set(); } } </script> </head> <body> <form action="#"> <input id="txt" type="text" value="分享互助" /><br /> <input type="button" id="bt" value="传递数据"/> </form> </body> </html>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能