簡體   English   中英

如何動態更改幀的src

[英]how to change the src of the frame dynamically

我有一個“ 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。 謝謝

您可以使用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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM