javascript - html 渲染事件

标签 javascript jquery

我正在使用 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/

相关文章:

javascript - 当另一个表单具有焦点时,在页面表单上禁用一个

JavaScript ( 函数 () { ... } ) ();

jquery - 应用程序再次关闭我打开我的应用程序它再次创建数据库

javascript - Bootstrap Carousel 自动功能在鼠标悬停在其上时不起作用?

javascript - 使用 Promise 在循环内调用 ajax

javascript - 无法获取 UIAStaticText 的值?

javascript - Chart.js ajax 与多个数据集

javascript - 如何浏览模块 ethereumjs-tx?

javascript - 使用 "getElementById"检索多个元素?

javascript - 如何通过单击一个来选择两个表格单元格?