2010-07-18 121 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

尝试把在一个

$(文件)。就绪(函数(){

而不是

$( “#鲍勃”)。就绪(函数(){