希望您可以控制填充#mapDirections 的JavaScript。您应该在数据到达后立即实施回调行为。
如果您没有该控件并且新数据是随机的,那么您需要确定一个时间间隔来轮询节点以获取新内容。
例如,假设 onNewMapDirections() 被调用以响应 DOM 中的某些事件:
function onNewMapDirections(newData) {
$('#mapDirections').html(newData);
//Add callback here
}
这可以通过在文档上绑定和触发自定义事件处理程序来轻松完成:
//Called when new directions are ready to add to DOM
function onNewMapDirections(newData) {
$('#mapDirections').html(newData);
$(document).trigger('checkMapDirections');
}
//Called in response to dispatched event
function onMapDirectionsUpdated(evt) {
if ($('#mapDirections').html().trim()) $('#mapReset').hide();
else $('#mapReset').show();
}
//Binds event
$(document).ready(function() {
$(document).bind('checkMapDirections', onMapDirectionsUpdated);
});
如果您无法在新的地图数据调用后立即嵌入回调,您仍然可以使用事件逻辑并实现一个定期调用的计时器
$(document).trigger('checkMapDirections');