有1.html和2.html  这两个页面,目标:打开1.html点击按钮,弹出2.html页面,input框里输入信息,点击确定,关闭窗口,信息传递给1.html的input框里,请问如何实现?

解决方案 »

  1.   

    你在1页面加一个超链接跳转到2页面,然后再2页面使用<%%>吧数据保存到session中,然后关闭2页面一页面可以得到值。最土的方法这是。
      

  2.   

    下面是两个页面的代码,纯html+js的,已在IE8上测试验证过。楼主要做的这个是很基本的功能,建议用jQuery的easyUI或extJs等成熟组件,既美观又方便。
    1.html的代码:<html>
     <head>
      <title>1</title>
      <Script language="javascript">
    function GetRequest() {
       var url = location.search;
       var theRequest = new Object();
       if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      strs = str.split("&");
      for(var i = 0; i < strs.length; i ++) {
     theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
      }
       }
       return theRequest;
    }
    function PageLoad(){
    var Request = new Object();
    Request = GetRequest();
    if(null == Request['inputTxt'] || "undefined"== Request['inputTxt'])
    document.getElementById("txtShow").value = "";
    else
    document.getElementById("txtShow").value = Request['inputTxt'];
    }
    function open2(){
    window.open("2.html");
    }
    </Script>
     </head>
     <body onload="PageLoad();">
      <input type="text" id="txtShow" />
      <input type="button" id="btnC" value="Change" onclick="window.open('2.html');" />
     </body>
    </html>2.html的代码:<html>
     <head>
      <title>2</title>
      <script type="text/javascript">
    function GoOne(){
    var inputTxt = document.getElementById("txt").value;
    window.opener.document.location = "1.html?inputTxt="+inputTxt;
    window.close();
    }
      </script>
     </head> <body>
      <input type="text" id="txt" />
      <input type="button" id="btnS" value="OK" onclick="GoOne();"/>
     </body>
    </html>
      

  3.   

    1.html的代码:<html>
     <head>
      <title>1</title>
      <Script language="javascript">
     function openWindow(){ 
        window.open("listAttas.jsp", "aaaa", "height=550,width=780,status=yes,toolbar=no,menubar=no,location=no");
            } 
    function getvalue(data){
    document.getElementById("txtShow").value=data;

    </Script>
     </head>
     <body >
      <input type="text" id="txtShow" />
      <input type="button" id="btnC" value="Change" onclick="openWindow();" />
     </body>
    </html>
     
    2.html的代码:<html>
     <head>
      <title>2</title>
      <script type="text/javascript">
    function GoOne(){
    window.opener.getvalue(document.getElementById("txt").value);
    window.close();
    }
     </script>
     </head> <body>
      <input type="text" id="txt" />
      <input type="button" id="btnS" value="OK" onclick="GoOne();"/>
     </body>
    </html>
      

  4.   

    上面主要是通过window.opener.getvalue(document.getElementById("txt").value);这段代码传值的,然后父窗体getvalue方法接收这个参数。其中listAttas.jsp就是你2.html,试试吧。第一次回复别人文本格式都给错了-_-|||