2013-06-03 185 views
1

如果你运行这个的jsfiddle在Chrome中,也将努力IFRAME,但IE和FF失败:http://jsfiddle.net/LbFPu/2/不能写在FF或IE浏览器,Chrome浏览器只

我想这事做如何每个引擎写入DOM?有没有办法等待以前的内容被写入?例如:

function firstMe(){ 
    $('body').append('<div id="first"></div>'); 
    // many other new elements appended 
} 

function thenMe(){ 
    $('#first').append('etc'); 
    // many of the recently appended elements being referenced 
} 

当为了叫,我想它会在Chrome中正常工作,但不是在IE & FF。由jsfiddle结果来判断。

以前有人曾经处理过这个问题吗?

+0

在小提琴上,在FireBug的FF中,在JS的第一行设置一个断点,然后输出将在那里。 –

回答

1

那只是因为你想写信给尚未加载入一个iframe,似乎铬更快:

$('body').append('<iframe id="upload"></iframe>'); 
var form = $('<form enctype="multipart/form-data" id="image_upload" action="index.php">' 
    + '<input type="file" accept="image/*" multiple name="img[]" id="image" />' 
    + '<br>' 
    + '<input type="submit" value="Upload images" class="upload" />' 
    + '</form>'); 

$('#upload').on('load', function() { 
    $(this).contents().find('body').append(form); 
}); 

FIDDLE

+0

完美,奇怪的是,有时它会闪烁,我可以看到插入的元素半秒钟,然后iframe会变成空白。 – localhost

-1

在FF,如果添加一个setTimeout()周围的最后一行它的工作原理:

相关问题