在一个页面中,包含多个iframe ,每个iframe里面包含着一个表单提交页面(如下图)。这样,就会有多个提交按钮。我想做一个提交按钮,同时触动每个iframe里的提交按钮,省的挨个点“提交”注:iframe里的提交页面是往其他网站提交的。

解决方案 »

  1.   

    给iframe 里的按钮添加onclick事件:  parent.submitAll(); //调用父窗口(主页面)的事件
    在主页面里添加submitAll方法
    function submitAll(){
      var ifms = document.getElementByTagName("iframe");
      for(var i=0; i<ifms.length; i++){
        var form = (ifms[i].document || ifms[i].contentWindow.document).getElementsByTagName("form")[0];
        if(form) form.submit();
      }
    }
      

  2.   


    function submitxx() {
    for (var i=0;i<window.frames.length;i++) {
    window.frames[i].forms[0].submit;
    }
    }
      

  3.   

    楼上二位的方法我都用了,但是没有成功啊。 
    我再说一下我的页面吧。
    首先有一个主页面 index.asp,里面有
    <form   name="test" action="123.htm">
    <iframe src=1.asp width=500 height=40 frameborder=0 scrolling=no></iframe>
    <iframe src=2.asp width=500 height=40 frameborder=0 scrolling=no></iframe>
    <input   name=bidwordform   type="button"   value="全部提交">   
    </form>还有两个个页面1.asp,2.asp 两个页面代码相同。
    里面有<FORM id=bidwordform name=bidwordform action=123.htm method=post>
         <INPUT id=newbidword style="WIDTH: 300px" maxLength=40 size=40 value="<%=rs("namese")%>" name=newbidword> 
         <INPUT id=event_submit_do_add_bidword onClick="javascript:return addBW();" type=submit value="添 加" name=event_submit_do_add_bidword>
         </form>我想达到的效果是,点击index.asp的“全部提交”按钮, 两个iframe 里的两个页面都会自动提交。
    点击主页面的"全部提交",就相当于分别点了两个子页面的“添加”按钮
      

  4.   

    window.frames["iframe的ID"].document.getElementById("iframe中的form的ID").submit();
      

  5.   

    index.html
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Index</title>
    <script type="text/javascript">
    function submitAll(){
    var ifms = document.getElementsByTagName('iframe');
    for (var i = 0; i < ifms.length; i++) {
    var win = (ifms[i].contentWindow || ifms[i]);
    win.submitMe();
    }
    }
    </script>
    </head>
    <body>
    <iframe src="form.html" width="500" height="40"></iframe>
    <iframe src="form.html" width="500" height="40"></iframe>
    <iframe src="form.html" width="500" height="40"></iframe>
    <iframe src="form.html" width="500" height="40"></iframe>
    <iframe src="form.html" width="500" height="40"></iframe>
    <iframe src="form.html" width="500" height="40"></iframe>
    </body>
    </html>form.html
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Form</title>
    <script type="text/javascript">
    function submitMe(){
    document.getElementById('testForm').submit();
    }
    function submitAll(){
    window.parent.submitAll();
    }
    </script>
    </head>
    <body>
    <form id="testForm" action="result.html">
    <input id="name" type="text" />
    <input type="submit" value="提交" />
    <input type="button" value="全部提交" onclick="submitAll()" />
    </form>
    </body>
    </html>result.html
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Result</title>
    </head>
    <body>
    Successfull!!!
    </body>
    </html>
      

  6.   

    submitMe是form.html如果不调用form.html的submitMe,submitAll可以改成function submitAll(){
    var ifms = document.getElementsByTagName('iframe');
    for (var i = 0; i < ifms.length; i++) {
    var form = (ifms[i].contentWindow || ifms[i]).document.getElementById('testForm');
    if(form) form.submit();
    }
    }
      

  7.   

    <form  name="test" action="123.htm"> 
    <iframe src=1.asp width=500 height=40 frameborder=0 scrolling=no> </iframe> 
    <iframe src=2.asp width=500 height=40 frameborder=0 scrolling=no> </iframe> 
    <input  name=bidwordform  type="button"  value="全部提交" onClick="doit()">  
    </form>
    <script language="javascript">
    function doit(){
    window.frames[0].bidwordform.submit();
    window.frames[1].bidwordform.submit();
    }
    </script>