我有一项服务可以从我的服务器中提取数据并将其填充到页面上的容器中。我试图在数据完全加载(图像和所有)到元素中后触发 onload 事件。这是一个例子:
<div id="DynamicContainer"></div>
<script type="text/javascript">
$.ajax({
url: "www.serverurl.com/service.ashx",
async: true,
success: function(data) {
var e = document.getElementById("DynamicContainer");
var $e = $(e);
$e.hide();
e.innerHTML = ""; // Clear contents
e.onload = function() { // Set load event
$e.show(); // (This isn't firing after the 'e.innerHTML = data' has completed loaded)
};
e.innerHTML = data; // The above "onload" event isn't firing after the contents have loaded.
}
});
</script>
有什么建议么?