简体   繁体   English

有什么方法可以在Jquery中调用函数“文档准备好之前”吗?

[英]Is there any way to call function 'before document ready' in Jquery?

我想在文档准备好之前调用函数,所以Jquery中有什么方法可以做到这一点?

If you simply call a function in the head tag it will execute immediately, before the DOM is even parsed (that's the 'problem' that ready solves). 如果仅在head标记中调用一个函数,它将在DOM解析之前立即执行(这是ready的“问题”)。

<!doctype html>
<html>
    <head>
        <script>alert(1)</script>
    </head>
    <body>
    </body>
</html>

Just call your function before the document ready statement. 只需在文档ready语句之前调用您的函数即可。

<script>
   thisWillFireImmediately();

   $(function() {
      thisWillFireOnDocumentReady();
   });
</script>

If you are using .hide() or display: none; 如果使用.hide()或显示:none; - the hiding of the divs will be displayed. -将显示div的隐藏。

try: 尝试:

visibility: hidden;

it worked for me after trying many other ways. 在尝试了许多其他方式后,它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery文档已准备就绪,并按键可以调用一个函数 - jQuery document ready and keypress to call one function jQuery / Javascript-在(文档)之前运行功能。准备好加载图像 - jQuery/Javascript - Run function before (document).ready for the purpose of loading an image jQuery允许光标在document.ready函数之前前进 - Jquery allow cursor to progress before document.ready function 如何在 document.ready 上调用多个 js 函数而不放置它们 jQuery(document).ready(function(){}); - How to call multiple js functions on document.ready without putting them jQuery(document).ready(function(){}); 如何使用setTimeout()调用jQuery(document).ready之外的函数? - How to call function outside of jQuery(document).ready with setTimeout()? 如何在jQuery中的文档就绪事件上自动调用函数 - How to call a function automatically on document ready event in jQuery 在jQuery中document.ready函数外部的事件上调用函数 - Call functions on events outside document.ready function in jquery 如何从 document.ready 调用 jQuery 函数 - How to call jQuery function from document.ready 尝试从 jquery $(document).ready 调用外部 js 中定义的 function - Try to call function defined in external js from jquery $(document).ready 如何从jquery中准备好的文档中调用ajaxComplete内部的函数? - How to call function inside ajaxComplete from document ready in jquery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM