Is $(document).ready necessary?

前端 未结 5 2084
太阳男子
太阳男子 2020-11-22 15:07

I saw this question in stackoverflow but do not feel that it was answered at all.

Is $(document).ready necessary?

I link all my javascripts at t

5条回答
  •  时光说笑
    2020-11-22 15:59

    No, if your javascript is the last thing before close you won't need to add those tags.

    As a side note, a shorthand for $(document).ready is the code below.

    $(function() {
    // do something on document ready
    });
    

    This question might be good. Did you read it? jQuery: Why use document.ready if external JS at bottom of page?

提交回复
热议问题