js获得子页面元素

来源:互联网 发布:手机qq变声软件 编辑:程序博客网 时间:2024/05/16 05:18

   在主页面中,增加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";

 

0 0
原创粉丝点击