How to combine multiple jquery functions

前端 未结 5 656
谎友^
谎友^ 2021-02-06 10:40

If you view the jquery code below you will see the famous $(document).ready(function(){ that starts the script off. I see this on pretty much all jquery code e

5条回答
  •  半阙折子戏
    2021-02-06 11:02

    You should try not to put too much inside the doc ready blocks. Yes you can have multiples of them however I stick to one if any. You can also put your script just before the closing body tag without the need for document ready.

    I advise breaking the code into separate functions. That way you can reuse them throughout your page at various stages. Then just use the doc ready block to trigger a call to that pages init function.

    You can also use $(function(){}); as a shorcut to $(document).ready(function(){});

    
    

提交回复
热议问题