首页 > Web开发 > 详细

js获得子页面元素

时间:2015-08-21 15:37:58      阅读:274      评论:0      收藏:0      [点我收藏+]

   在主页面中,增加iframe子页面,如果需要获得子页面的元素则可以使用javascript的contentWindow来获得,注意iframe和frameset必须添加id,具体例子如下:

mainindex.jsp中添加子页面

<iframe id="indexIframe" src="jsp/main/main.html" width=100% height=100% scrolling="no" frameborder="0"></iframe>

main.html中添加frameset

<frameset rows="102,*" frameborder="no" border="0" framespacing="0" >
 <frame src="navigation.jsp" id="topFrame" name="topFrame" scrolling="No" id="topFrame" style="overflow-y:hidden;overflow-x:hidden"/>
  <frame src="../live/gplayer/bin/gplayer.jsp" name="mainFrame" id="mainFrame" scrolling="No" style="overflow-y:hidden;overflow-x:hidden"/>
</frameset>

navigation.jsp页面中存在某个元素

<img id="moreImg" src="images/web/more_available.png" style="cursor:pointer" onclick="popupMenu()"></img>

在主页面mainindex.jsp中获得img元素,利用javascript可以这样获得

 var indexiframe=document.getElementById("indexIframe");
  var topframe=indexiframe.contentWindow.document.getElementById("topFrame");
  var moreImg=topframe.contentWindow.document.getElementById("moreImg");
  moreImg.src="images/web/more_available.png";

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

js获得子页面元素

原文:http://blog.csdn.net/adgjlxxx/article/details/47834621

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!