我想这可能是非常明显的,但我对前端非常了不起
场景如下:每当用户点击一个按钮时,我都需要
通过blockUI来阻止页面
2 - 清楚一些东西
3加载一些东西
4 - 解锁页面
让我们有一个片段,类似于我目前的方法:
function reload_data()
{
//block
$.blockUI({ message: $('#spinner_div') , css: { top: '50%' , left:'50%' , border:'none'} });
//clear stuff
$('#my_kpi' ).text(''); //this empty an anchor
$('#my_report iframe').attr('src',''); //this empty an iframe
//load stuff
$('#my_kpi' ).text('loaded'); //this sets an anchor
$('#inf_prioridad_estado iframe').attr('src','foo.php'); //this loads an iframe
//unblock
setTimeout(function(){ alert("I would like not to unblock until iframes are loaded");},2000);
setTimeout($.unblockUI, 2000); //will be blocked unless for 2 seconds
console.log('unblocked');
}

我知道(想的是......)发生了什么,但我不知道如何解决它:
$()ATTR(' SRC'' foo.php&#39)。确实已经执行了,但在实际加载iframe之前会继续下一个语句
任何想法?
非常感谢你!
答案 0 :(得分:1)
设置iframe的src
属性后,您需要侦听加载事件:
// Set number of frames to be loaded
// This could be done with a jquery selector getting iframe count
var framesToLoad = 2;
function tryUnblockUI() {
// Frame loaded, decrement framesToLoad count
framesToLoad--;
// Once all frames are loaded, unblock UI
if (frameLoadingCount === 0) {
//unblock ui here
}
}
// Load frame 1
$('#inf_prioridad_estado iframe')
.attr('src', 'foo.php')
.on('load', tryUnblockUI);
// Load frame 2
$('#inf_prioridad_estado_2 iframe')
.attr('src', 'foo.php')
.on('load', tryUnblockUI);