2010-07-18 119 views
1

下我的網頁上不起作用:JQUERY iFrame,使用警報,沒有警報不起作用 - 奇怪?爲什麼

$("#bob").ready(function() { 
    $("#bob").contents().find(".findme").css("background", "red"); 

    $(document.getElementById('bob').contentWindow.document).find('.findme').bind("mousedown", function() { 
     alert( $(this).text()); 
    }); 
}); 

但如果我增加一個Alert,我以爲增加了延遲的一些類型,讓iframe中運行JS繼續之前,它的工作?

$("#bob").ready(function() { 
    alert(1) 
    $("#bob").contents().find(".findme").css("background", "red"); 

    $(document.getElementById('bob').contentWindow.document).find('.findme').bind("mousedown", function() { 
     alert( $(this).text()); 
    }); 
}); 

是延遲是什麼使它的工作,不應該準備好照顧這個?另外,有沒有辦法讓上面的LIVE,所以時間不是問題?

+1

請參閱[jQuery .ready在動態插入iframe](http://stackoverflow.com/questions/205087/jquery-ready-in-a-dynamically-inserted-iframe)。它應該工作,如果您使用load '準備好'。 – 2010-07-18 01:08:25

回答

2

嘗試把在一個

$(文件)。就緒(函數(){

而不是

$( 「#鮑勃」)。就緒(函數(){