jquery source's position in html file is important or not

后端 未结 5 949
再見小時候
再見小時候 2021-01-21 16:38

This is an example of click button to pop up an alert.



        
5条回答
  •  爱一瞬间的悲伤
    2021-01-21 16:52

    Yes its true that you should include your script at the bottom of the page, In your case you are calling jquery function even before core library has loaded. You will have to include your script after jquery library because functions are defined in the library and as the code executes these function has to be referenced

    //At the bottom of the page
    
    
    
    

    However, when I test on http://jsfiddle.net/eSud7/3/ the position of the script is not important.

    Thats because you have selected to load jquery library on load(Look at the left hand side), so your library is included in the DOM on body load i.e. in your fiddle your giving position of library is redundant

    Update on OP comments

    
    

    AT the bottom of the page

    //Contains all the jquery functions
        
    

提交回复
热议问题