日期:2014-05-16  浏览次数:20343 次

关于iframe的小问题
HTML code

<table width="99%"  height="540px">
                              <tr>
                                <td  width="99%" align="left" valign="top"  style="border:1px solid #B4C9C6;height:180px;width:750px;background-color: #fff;">
                                    <div style=" overflow:auto;height:100%;">
                                        <s:form id="searchForm" target="myframe" action="searchSelectedQuestion" namespace="/data" onsubmit="return checkInput();">
                                            <input type="submit" value="搜索" name="advencesearch" id="search-submit" style="margin-top: 10px"/>
                                            
                                            <table  class="t2"  id="showQuestion">
                                                
                                            </table>
                                        </s:form>
                                    </div>
                                </td>
                              </tr>
                              <tr>
                                <td style="border:1px solid #B4C9C6;height:340px;background-color: #fff;">
                                    <iframe onload="initPage()" width="100%" height="100%" frameborder="0" id="myframe" name="myframe" scrolling="auto">
                                        
                                    </iframe>
                                </td>
                              </tr>
                        </table>



------解决方案--------------------
parent.document.searchForm....
这样操作试过吗?
------解决方案--------------------
首先楼主要把form表单里面的s标签删除,不然js不能识别该标签的,s应该是jsp里面的标签吧,以下是我写的方法,分别用js和jquery实现,希望对楼主有所帮助。
1、你先删除s标签,修改为
HTML code

<form id="searchForm" target="myframe" action="searchSelectedQuestion" namespace="/data" onsubmit="return checkInput();">
                                            <input type="submit" value="搜索" name="advencesearch" id="search-submit" style="margin-top: 10px"/>
                                            
                                            <table  class="t2"  id="showQuestion">
                                                
                                            </table>
                                        </form>

------解决方案--------------------
另外附上父窗口与iframe子窗口之间传值的方法,希望对楼主有所帮助。

在父窗口中获取iframe中的元素
1、js代码

(1)第一种方法
格式:window.frames["iframe的name值"].document.getElementById("iframe中控件的ID").click();
//window.frames["mainIframe"].document.getElementById("iTextValue").value;
//触发iframe中的元素的单击事件
//window.frames["mainIframe"].document.getElementById("iTestClick").click();

(2)第二种方法
格式:
var obj=document.getElementById("iframe的ID").contentWindow;
var ifmObj=obj.document.getElementById("iframe中控件的ID");
ifmObj.click();
//var obj=document.getElementById("mainIframe").contentWindow;
//var ifmObj=obj.document.getElementById("iTestClick");
//ifmObj.click();

2、jquery代码

(1)第一种方法