zoukankan      html  css  js  c++  java
  • js窗体间传值

    A页面传值给 B页面
    页面A
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <HEAD>
      <TITLE> page A </TITLE>
      <script language="javascript">
          function newWin() {
              var obj = new Object();
              obj.name = "zhangsan";
              obj.age = "20";
              var str = window.showModalDialog("B.aspx", obj, "dialogWidth=400px;dialogHeight=300px");
              
          }
      </script>
    </HEAD>
    
    <BODY>
      <input type="text" id="mytext">
      <input type="button" value="button" onclick="newWin();">
    </BODY>
    </html>

    页面B

    <html xmlns="http://www.w3.org/1999/xhtml">
    <HEAD>
      <TITLE> Page B </TITLE>
      <script language="javascript">
          function colseWin() {
              var obj = window.dialogArguments;
              alert("您传递的参数为:" + obj.name);
          }
      </script>
    </HEAD>
    
    <BODY>
         <input type="text" id="mytext">
      <input type="button" value="保存并关闭" onclick="colseWin();">
    </BODY>
    </html>

    上面这样,当B页面打开后,点击 “保存并关闭” 按钮,会显示  A页面传递过来的zhangsan



    华丽分割线----------------------------------------------------------------------------------------------------------------------

    子页面B 传值给 父页面A


    主页面:

    <!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>

        <title>无标题页</title>

        <script type="text/javascript">

        function OpenWin()

        {

          window.open("father.htm","aa","","");

        }

        </script>

    </head>

    <body>

        <input id="T1" type="text" />

        <input id="Button1" type="button" value="提交" onclick="OpenWin();" />

    </body>

    </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>

        <title>无标题页</title>

        <script type="text/javascript">

        function ReturnVal()

        {

          window.opener.document.getElementById('T1').value=document.getElementById('Text1').value;

          window.close();

        }

        </script>

    </head>

    <body>

        <input id="Text1" type="text" />

        <input id="Button1" type="button" value="关闭" onclick="ReturnVal();" />

    </body>

    </html>


    PS:以前我记得 通过 showModalDialog和 returnVal 可以实现,但是现在 Chrome是不支持 showModalDialog了。并且window10自带的IE Edge 好像也不支持了。

    那么怎么传递一个var obj=new Object() 对象呢? 希望了解的朋友 告知一下


  • 相关阅读:
    java处理jqueryGantt甘特图数据的task.depends依赖规则方法
    中国行政区划表,包括34个省、直辖市的所有数据 mysql数据
    使用mybatis的resultMap进行复杂查询
    intel 酷睿core系列cpu的类型:U M H HQ MQ
    mybatis问题。foreach循环遍历数组报错情况,及其解决方法
    Android开发 DownloadManager详解
    Android开发 WorkManager详解
    Android开发 在不使用ItemTouchHelper的情况下实现ItemView的左右滑动
    AndroidStudio ViewBinding详解
    Android开发 滚轮View第三方框架
  • 原文地址:https://www.cnblogs.com/hanjun0612/p/9779918.html
Copyright © 2011-2022 走看看