0

我有一个“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。谢谢

4

1 回答 1

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>
于 2013-06-03T11:32:11.680 回答