What happens when you have two jQuery $(document).ready calls in two JavaScript files used on the same HTML page?

前端 未结 5 1425
生来不讨喜
生来不讨喜 2020-12-15 03:50

I have a question on jQuery $(document).ready

Let\'s say we have a HTML page which includes 2 JavaScript files



        
5条回答
  •  旧巷少年郎
    2020-12-15 04:12

    1. Both will get fired
    2. The value of the variable will be 2 once all the dust has settled.
    3. The main thing which isn't recommended is using 2 different JS files, as Google PageSpeed, and Yahoo YSlow recommends, it's best to have all your Javascript codes in the same file. as far as same event handlers, well, in all honesty, I see no reason why to do that, and it'll only make your code readability lousier.
    4. I have no answer for that.

提交回复
热议问题