如果iframe重新加载时焦点仍在输入上,是否重新运行jQuery函数



我有一个输入字段,当focus启动jQuery函数来隐藏iframe中的一些内容时,它可以很好地工作。但是,如果在输入字段仍处于焦点时重新加载/刷新iframe内容,则jQuery函数将不会再次启动。如果在重新加载iframe内容后输入仍然处于焦点,是否可以重新运行下面的jQuery?

$('#_customize-input-checkin\[message\]').focus(function() {
var $iframe = $("#customize-preview iframe").contents();
$("#alert_check_in_notification_sent", $iframe).css("display", "block");
$("#check-in-wrap", $iframe).css("display", "none");
});

您可以处理iframe onload事件来执行相同的逻辑。尝试以下操作-

function exec(){
var $iframe = $("#customize-preview iframe").contents();
$("#alert_check_in_notification_sent", $iframe).css("display", "block");
$("#check-in-wrap", $iframe).css("display", "none");
}
$('#_customize-input-checkin\[message\]').focus(function() {
exec();
});
$("#customize-preview iframe").load(function(){
if($('#_customize-input-checkin\[message\]').is(":focus"))    
exec();
});

最新更新