我有一个“cars.html”HTML文件,框架集中有三个框架
<frameset id="help" rows="10%,5%,90%">
<frame id="pageTitle" frameborder=0 scrolling=no src="cars_pageTitle.html">
<frame id="pageMenu" frameborder=0 marginheight="0" src="cars_pageMenu.html">
<frame id="pageContent" frameborder=0 marginheight="0" src="#">
</frameset>
“cars_pageMenu.html”有菜单栏
我将它分配给第二帧的src
<script type="text/javascript">
function carRequestMenu()
{
alert(document.getElementById("pageContent"));
document.getElementById("pageContent").src='cars_requestMenuContent.html';
}
</script>
<BODY>
<div id="pageToolbar" style="width=100%;height:10px;background-color:FF3333">
<menu type="toolbar" style="margin-left: 0px;margin-bottom: 0px">
<button type="button" onclick="carRequestMenu()">Request a Car</button>
</menu>
</div>
</BODY>
当我点击“请求汽车”按钮时,调用carRequestMenu()函数 警报显示空值。我无法动态更改src。 谢谢
答案 0 :(得分:1)
您可以使用window.open并指定目标名称:
<frameset id="help" rows="10%,5%,90%">
<frame id="pageTitle" frameborder=0 scrolling=no src="cars_pageTitle.html">
<frame id="pageMenu" frameborder=0 marginheight="0" src="cars_pageMenu.html">
<frame id="pageContent" name="pageContent" frameborder=0 marginheight="0" src="#">
</frameset>
<script type="text/javascript">
function carRequestMenu()
{
window.open('cars_requestMenuContent.html','pageContent');
}
</script>
<BODY>
<div id="pageToolbar" style="width=100%;height:10px;background-color:FF3333">
<menu type="toolbar" style="margin-left: 0px;margin-bottom: 0px">
<button type="button" onclick="carRequestMenu()">Request a Car</button>
</menu>
</div>
</BODY>