问题是这样,下面的代码是我的主页面,主页面里面有个搜索框,然后就是一个iframe我现在想实现如下两个功能:
1.把主页面中的搜索框中的数据传递到iframe里面
2.然后返回的结果,从iframe中返回到主页面当中(或者在主页面当中再建立一个iframe,返回给它也行)我写的代码如下,下面代码中“XXXXX”应该是要写的东西,本人新手,搞不定阿PS:大侠们最好给出具体代码,小弟才疏学浅能力有限!<html>
<head><title>wlw.com</title></head>
<body>
<form action = "#" onsubmit = "XXXXXX" style = "display: inline-block; white-space: nowrap;" id = "searchForm">
  <table cellspacing = "0" cellpadding = "0">
  <tr>
    <td>
         <input id = "strInput" type = "text" style = "width: 400px; height: 30px;">
    </td>
    <td>
         <button type = "submit" id = "searchButton" style = "width:90px; height: 30px;"></button>
    </td>
 </tr>  </table>
</form><hr><iframe name="inside" src="index-clear.html" cols="30%,*" height=600 width=1100 align=right scrolling=no frameborder=yes>
</iframe>
</body>
</html>

解决方案 »

  1.   

                                <iframe frameborder="no" hidefocus="" style="width: 100%; height:480px;" onload="" id="mainFrame" name="mainFrame" src="xx.htm"></iframe>    function searchmail()//单击按钮执行事件
        { 
     
             document.getElementById("mainFrame").src="list.html?keys="+$("#keys1").val()+"&id=search"+"&title=搜索结果";
        }
      

  2.   

    你的主页面的搜索框还应该配有一个按钮吧, 那么你在按钮的单击事件中用querystring的方式传值给要在你的iframe中显示的页面,然后在这个页面中取出querystring的值就可以了,这时你可以在要在你的iframe中显示的那个页面中的任何地方使用这个querystring的值.
      

  3.   

    <html>
    <head><title>wlw.com</title>
    <script type="text/javascript">
    function XXXXXX(){
        document.inside.window.document.body.innerHTML=document.getElementById("strInput").value;
        document.inside.window.onresize=function(){parent.window.document.getElementById("strInput").value="return value"};
        document.inside.window.resizeTo(1100,500);
    }
    </script>
    </head>
    <body>
    <form action = "#" onsubmit = "XXXXXX();return false;" style = "display: inline-block; white-space: nowrap;" id = "searchForm">
      <table cellspacing = "0" cellpadding = "0">
      <tr>
      <td>
      <input id = "strInput" type = "text" style = "width: 400px; height: 30px;">
      </td>
      <td>
      <button type = "submit" id = "searchButton" style = "width:90px; height: 30px;"></button>
      </td>
     </tr>  </table>
    </form><hr><iframe name="inside" src="photo3.aspx" cols="30%,*" height=600 width=1100 align=right scrolling=no frameborder=yes>
    </iframe>
    </body>
    </html>
      

  4.   

    main.html
    <html>
    <head>
    <script type="text/javascript">
    function getMsg(){
    var el = document.getElementById("msg");
    var txt = document.frames['inside'].document.getElementById('txts');
    txt.value = el.value;
    }
    </script>
    </head>
    <body>
    <input type="text" id="msg" />
    <input type="button" onclick="getMsg()" value="button" /><br/>
    <iframe name="inside" id="inside" src="1.html" cols="30%,*" height=600 width=1100 align=right scrolling=no frameborder=yes>
    </iframe>
    </body>
    </html>
    1.html
    <html>
    <head>
    <script type="text/javascript">
    function getMsgs(){
    var el = parent.document.getElementById("msg");
    var txt = document.getElementById("txts");
    el.value = txt.value;
    }
    </script>
    </head>
    <body>
    <input type="text" id="txts" />
    <input type="button" value="button" onclick="getMsgs()"
    </body>
    </html>
      

  5.   


    <html>
    <head><title>wlw.com</title></head>
    <script type="text/javascript">
    var theFormSubmit=function(){
    searchForm.action = "index-clear.html?s=" + document.getElementById("strInput").value;
    searchForm.submit();
    }
    </script>
    <body>
    <form method="get" target="inside" style = "display: inline-block; white-space: nowrap;" id = "searchForm">
      <table cellspacing = "0" cellpadding = "0">
      <tr>
      <td>
      <input id = "strInput" type = "text" style = "width: 400px; height: 30px;">
      </td>
      <td>
      <button type = "submit" id = "searchButton" style = "width:90px; height: 30px;" onclick="theFormSubmit()"></button>
      </td>
     </tr>
      </table>
      结果:<input id="result" type="text" />
    </form><hr><iframe name="inside" src="dex-clear.html" cols="30%,*" height=600 width=1100 align=right scrolling=no frameborder=yes>
    </iframe>
    </body>
    </html>
    index-clear.html<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
     <head>
      <title> New Document </title>
     </head> <body>
      提交处理
      <script type="text/javascript">
    parent.document.getElementById("result").value="处理结果";
      </script>
     </body>
    </html>
      

  6.   

    哥们儿你的方案是不是1.html里面也有个按钮才行阿?
      

  7.   

    我在index-clear.html里面怎么收strInput这个字符串阿?
      

  8.   

    不用 1.html里的按钮只是给你演示在子页中获取父页中的元素
      

  9.   


    那我在1.html里面怎么收主动收阿?也就是父窗口的按钮一按下,1.html里面就接受这个信息
    你在1.html里面也是被动的接受阿
      

  10.   

    index.html<html>
    <head><title>wlw.com</title>
    <script>
    String.prototype.trim = function() {
      return this.replace( /^\s+/g, "" ).replace( /\s+$/g, "" );
    } function set_iframe(){
    var strinp=document.getElementById("strInput");
    var value = strinp.value.trim();
    if(value == ""){
    return false
    }else{
    inside.document.getElementById("ifr_text").value = ("搜索框输入:"+value);
    alert("iframe内的值已经设置为");
    return false;
    }
    }
    </script>
    </head>
    <body>
    <form action = "#" onsubmit = "return set_iframe();" style = "display: inline-block; white-space: nowrap;" id = "searchForm">
      <table cellspacing = "0" cellpadding = "0">
      <tr>
      <td>
      <input id = "strInput" type = "text" style = "width: 400px; height: 30px;">
      </td>
      <td>
      <button type = "submit" id = "searchButton" style = "width:90px; height: 30px;"></button>
      </td>
     </tr>  </table>
    </form><hr><iframe name="inside" src="index-clear.html" cols="30%,*" height=600 width=1100 align=right scrolling=no frameborder=yes>
    </iframe>
    </body>
    </html>
    index-clear.html我是iframe中的数据框,我来接收父页面传给我的值:<input type="text" id="ifr_text" value="">
    <script>
    window.onload=function(){
    var sto = setInterval(function(){
        var te = document.getElementById("ifr_text");
        if(te.value != ""){
         parent.document.getElementById("searchButton").value="改变";
         alert("接受到父页面的值处理后,改变父页面按钮的值");
         clearInterval(sto);
        }
    },1000)
    }
    </script>