一、 iframe 获得 父页的 元素:
$('#主页元素的ID', parent.document).val();
二、 iframe 获得 父页的 方法:
parent.父页方法名字();
三、 父页 获得 iframe 的 元素:
1. 通过iframe的name来获得(注:不是ID,是name):
$(window.frames["iframe的name"].document).find("#ifrme中元素的ID").val();
2. 通过iframe的顺序来获得:
var ii = document.getElementsByTagName_r('iframe')[0];
var total = $('#iframe中元素的ID', ii.contentWindow.document).val();
3. $('#iframe中元素的ID', window.frames["iframe的name"].document).val();
四、 父页 获得 iframe 方法:
window.frames["iframe_blBooking_name"].ifrme中的方法名字() ;
五、 父页 刷新 iframe:
window.frames["iframe_blBooking_name"].location.reload();
六、 iframe 获得父亲也中另一个iframe
1. js方法:
parent.frames['iframe_DIYTable'].document.getElementById('west_DIYTable');
2. jquery方法:
$(parent.frames['iframe_DIYTable'].document).find("#west_DIYTable").html();
七、 iframe 中获得当前 iframe 的ID
$(window.parent).find("iframe[src='b.html']").prop("id"); 父页
<body>
<input id="father" value=" i am the input in father"/>
<iframe id ="iframe_id" name="iframe_name" frameborder=0
src="${ctx}/iframe-EasyUi/blbooking_iframe.jsp"></iframe>
</body>
<script tyle="text/javascript language="javascript">
// 获得iframe中的元素值
var child1 = $(window.frames["iframe_name"].document).find("#child").val();
var tmp = document.getElementsByTagName('iframe')[0];
var child2= $('#child', tmp.contentWindow.document).val();
var child3 = $('#child', window.frames["iframe_name"].document).val();
// 获得iframe中的方法
window.frames["iframe_name"].childFunc() ;
// 重新加载iframe
window.frames["iframe_blBooking_name"].location.reload();
function fatherFunc(){
alert("i am the function in father!");
}
</script>
iframe:
<body>
<input id="child" value=" i am the input in iframe"/>
</body>
<script tyle="text/javascript language="javascript">
// 调用父页的元素值
var father_value= $('#father', parent.document).val();
// 调用父页的方法
parent.fatherFunc();
function childFunc(){
alert(i am the function in iframe);
}
</script>