日期:2014-05-17  浏览次数:20614 次

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

------解决方案--------------------
下面是两个页面的代码,纯html+js的,已在IE8上测试验证过。楼主要做的这个是很基本的功能,建议用jQuery的easyUI或extJs等成熟组件,既美观又方便。
1.html的代码:
HTML code

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