第四周
本周学习内容
网页iframe子页面与父页面数据传输
第一页面设置iframe和一个接受改变的input文本
<div class="middle2" id="middle2"> <iframe height="750px" width="90%" id="IFeditValue" name ="IFeditValue"></iframe> <input id ="childin" type="hidden" value="芗城区"> </div>
jq设置此iframe
Url="nowtable.jsp?nowcity='"+$("#childin").val()+"'";
$("#IFeditValue").attr('src',Url);
当选中某一条记录,需要更新iframe URL 时
Url="nowtable.jsp?nowcity='"+e.poi.name+"'";
$("#IFeditValue").attr('src',Url);
子页面设置点击事件
<script>
<%
for(int j=0;j<ko;j++){
%>
var divm= document.getElementById("div<%=j%>");
divm.onclick=function (){
var text = document.getElementById("scence<%=j%>").innerHTML;
console.log(text);
var win_fu = window.parent;
console.log(win_fu);
var text_fu = win_fu.document.getElementById("childin");
console.log(text_fu);
text_fu.value = text;
}
<%}%>
</script>
主页面对iframe添加点击事件
var iframe = document.getElementById('IFeditValue'); iframe.onload = function() { iframe.contentDocument.onclick = function() { placeSearch.search(document.getElementById("childin").value); }; }

浙公网安备 33010602011771号