我試圖通過將iframe src分配給一個變量來打開不同的iframe窗口,當頁面最初加載時應該只顯示兩個按鈕,當我點擊按鈕時,一個iframe應該得到負載取決於哪個按鈕被按下時,我試圖做這樣的事情創建按鈕和創建內部框架,但它不工作根據不同的按鈕點擊打開不同的iframe
<button id="b1">Button 1</button>
<button id="b2">Button 2</button>
<iframe scrolling="no" src="whatnext">
</iframe>
<script>
var b1 = document.getElementById('b1'), b2 = document.getElementById('b2');
var x = "Hello!";
function showX() {
var whatnext;
if b1.onclick==true
whatnext= "http://community.sitepoint.com/" style="border: 0px none; height: 1555px; margin-left: -116px; margin-top: -25px; width: 930px;"
elseif b2.onclick=true
whatnext= "http://community.sitepoint.com/" style="border: 0px none; height: 555px; margin-left: -116px; margin-top: -25px; width: 330px;"
}
</script>
and another piece of trial is
<button id="b1">Button 1</button>
<button id="b2">Button 2</button>
<iframe scrolling="no" src="x" style="border: 0px none; height: 1555px; margin-left: -116px; margin-top: -25px; width: 930px;">
</iframe>
<script>
var b1 = document.getElementById('b1'), b2 = document.getElementById('b2');
var x ;
function showX() {
src="https:http://stackoverflow.com";
}
b1.onclick = function() {
x = "http://stackoverflow.com;
showX();
};
b2.onclick = function() {
x = "www.sitepoint.com";
showX();
};
</script>
感謝很大的幫助兄弟........我用這個很多努力,從相當長 – user1597336 2014-10-09 13:48:19
你好博揚,解決的辦法是偉大的,但還是有一點這個腳本沒有提供的是,爲不同的按鈕點擊製作不同的iframe結構,每個按鈕加載不同的iframe,但iframe的大小也必須與按鈕不同,例如。對於第一個按鈕單擊ifram應加載寬度= 500和高度= 400,但對於下一個按鈕單擊它應該是widht = 650和高度= 350 – user1597336 2014-10-11 10:09:33
您是否使用jQuery解決方案或JavaScript? – 2014-10-13 09:22:57