我正在使用 jQuery AJAX 调用将一些代码附加到我的页面。此代码是 html 和 javascript 的混合。但我希望仅当 html 部分准备就绪时才执行 javascript。但是当呈现附加的 html 时会引发什么事件?
这是一个例子:
<table id="sampleTable">
...
</table>
<script>
// this code should be executed only when sampleTable is rendered
$('#sampleTable').hide();
</script>
最佳答案
使用 jQuery ready() 事件:
$(document).ready(function() {
$('#sampleTable').hide();
}
<edit>
似乎不可能在除 Document 之外的任何其他对象上调用就绪事件,我的坏 </edit>
如果您谈论的是在成功的 Ajax 请求后触发的事件,这是一个选项:
$('#sampleTable').ajaxComplete(function() {
$(this).hide();
});
或者只是硬编码要显示的表格样式:无;...
关于javascript - html 渲染事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2541398/