关于iframe的小问题
<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>
<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)第一种方法
格式:$("#iframe的ID").contents().find("#iframe中的控件ID").click();
//$("#mainIframe").contents().find("#iTextValue").val();
(2)第二种方法
格式:$("#iframe中的控件ID", window.frames("frame的name").document).click();
//$("#iTextValue",window.frames["mainIframe"].document).val();
在iframe中获取父窗口的元素
1、js代码
格式:window.parent.document.getElementById("父窗口的元素ID").click();
//window.parent.document.getElementById("testClick").click();
2、jquery代码
格式:$('#父窗口中的元素ID', parent.document).click();
//$('#textValue', parent.document).val();
[解决办法]
window.parent.document.getElementById("searchForm表单中某元素的ID");
[解决办法]
window.parent 父窗口
top 顶层窗口
[解决办法]
结贴给分。。。。