jQuery load() function doesn't work

前端 未结 3 855
失恋的感觉
失恋的感觉 2021-01-17 01:48

I am new to the world of JavaScript and I\'m trying to use the function load() to insert another html file. It\' a little bit hard to explain, here is the code:



        
3条回答
  •  有刺的猬
    2021-01-17 02:03

    I do not believe the code you have presented has any faults in any way. I believe it is to do with your loading of the JQuery library, as with the following code I achieved these results:

    index.html

    
        
            
            
        
        
            

    HELLO

    NEWS

    news.html

    
        
        

    HELLO STACK OVERFLOW!!!

    Before click:

    enter image description here

    After click:

    enter image description here

    However, when I was building this example I first tried using the Google APIs version of JQuery and found that I could not currently connect to the API. Therefore I believe the solution to your problem is to go to this website: http://code.jquery.com/jquery-1.11.1.js and copy and paste everything into a text file called 'jquery.js'. Then add the following to the head tag of your main HTML file:

    
    

    Make sure that 'jquery.js' is in the same directory as the main HTML file of your project otherwise this will not work. Hope this helps :)

提交回复
热议问题