日期:2014-05-16  浏览次数:20357 次

父页面如何用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=.....);