2012-12-02 25 views
0
$("div[id^='BlockHeading']").live("click", function() { 

    var text = $(this).text().toString(); 
    if ($(this).next().css("display") == "none") { 
     $(this).empty(); 
     $(this).html("" + text + " <img src='../img/109041_25936_16_chevron_collapse_icon.png' height='12' width='12' style='float:right'>") 
     iframeresize(); 
     $(this).focus(); 
    } else { 
     $(this).empty(); 
     $(this).html("" + text + " <img src='../img/109041_25936_16_chevron_collapse_iconDown.png' height='12' width='12' style='float:right'>") 
     iframeresize(); 
     $(this).focus(); 
    } 
    jQuery(this).next(".content").slideToggle(100); 
}); 

我試圖在發生事件後調整IFRAME的大小。以上顯示了一個這樣的事件。但問題出現在函數iframeresize()中 - 如果我在調用函數之前或在函數本身中激活了alert(),並且它在Firebug中的debug-window中工作 - 但根本不起作用,除非alert()是目前...腳本停止執行,如果我刪除警報()

我錯過了什麼?

編輯 代碼爲iframeresize()

function iframeresize() { 
    $("#frame1", parent.document).css("height", $("#form1").height() + 100); 
    $("#container", parent.document).css("height", $("#form1").height() + 100); 
} 
+0

我的猜測是時間 - 你可以嘗試從你插入的html裏面調用'iframeresize'嗎? – sje397

+0

好的。讓我嘗試一個.. – user1666443

+0

對不起,但我該怎麼做...? – user1666443

回答

0

嘗試從超時調用它,讓代碼的其餘部分繼續執行。

... 
setTimeout(iframeresize, 10); 
... 
+0

nope ...沒有工作 – user1666443

0

我刪除了$(this).empty(),因爲無論如何,您將新的html分配給元素。 測試此代碼,證明它可以工作(http://jsfiddle.net/Zt3eP/17/) 因此,代碼的其他部分可能存在問題,而不是您顯示的內容。

$("div[id^='BlockHeading']").live("click", function() { 
    var text = $(this).text().toString(); 
    if ($(this).next().css("display") == "none") { 
     $(this).html("" + text + " <img src='../img/109041_25936_16_chevron_collapse_icon.png' height='12' width='12' style='float:right'>") 
     iframeresize(); 
     $(this).focus(); 
    } else { 
     $(this).html("" + text + " <img src='../img/109041_25936_16_chevron_collapse_iconDown.png' height='12' width='12' style='float:right'>") 
     iframeresize(); 
     $(this).focus(); 
    } 
    $(this).next(".content").slideToggle(100); 
}); 
function iframeresize(){ 
    console.log('resize'); 
} 
​