簡體   English   中英

Javascript,從另一個iframe更改ElementById值

[英]Javascript to change ElementById value from another iframe

只是想知道是否有可能從同一頁面上加載的另一個iframe更改一個iframe中的標簽或元素?

我在頁面上有2個iframe:

<iframe id="leftMenu" src="menu.htm" STYLE="top:90px" NAME="menu" width="270px" frameborder="0"></iframe>

<iframe src="page.htm" STYLE="top:90px" NAME="AccessPage" width="100%" height="100%" frameborder="0"></iframe>

從page.htm(第二iframe)中,我希望能夠通過ID將值更改為第二iframe上的其他內容。

例如:menu.htm(第一個iframe)在該頁面上有一個標簽。

<label id="test">test1234</label>

我要從page.htm(第二個iframe)更改該標簽的值。

我嘗試執行以下操作,但沒有運氣:

document.getElementById('leftMenu').contentWindow.document.getElementById('test').value = 'test successful';

像這樣使用window.parent

    window.parent.document.getElementById('leftMenu').contentWindow.document.getElementById('test').innerHTML = "Replaced Successful!"

而不是.value使用.innerHTML

查看有效的演示: http : //jsfiddle.net/rathoreahsan/G2un4/4/

經過本地測試,也可以正常工作。

暫無
暫無

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

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