读书人

父页面怎么用JS更改iframe中指向页面中

发布时间: 2013-03-12 11:19:35 作者: rapoo

父页面如何用JS更改iframe中指向页面中li的背景??在线等
如:

父页面index.html代码:

<div id="cnWholeDiv">
<div id="cnTopDiv">

<iframe id="cTopFrame" src="top.html" scrolling="no" frameborder="0" width="1024px" height="220px;">
</iframe>

</div>

------------------------------

top.html代码:

<div id="middleDiv">
<div id="mBgDiv">
<ul>
<li id="homeId" value="1">主页</li>
</ul>


如何通过js,在index.html中改变top.html中标签li的背景,谢谢!自己试过类似代码

var frame1=document.getElementById("cTopFrame");
alert(frame1.document.getElementById("homeId").style.backgroundImage=.....);
好像不行。。。请指教



[解决办法]
这样试试:


var frame1=document.getElementById("cTopFrame");
alert(frame1.contentWindow.document.getElementById("homeId").style.backgroundImage=.....);

读书人网 >JavaScript

热点推荐