How to use jquery in ASP.​NET Core

后端 未结 3 537
一个人的身影
一个人的身影 2020-12-29 23:19

I created a ASP.NET core template and wrote a jquery script. When I look at the page I see that jquery is loaded into the page, but the script doesn’t run. I looked at the A

3条回答
  •  再見小時候
    2020-12-29 23:55

    I suspect your jquery is loaded after the rest of the page content.

    This means that you cannot reference jquery objects as the library has not been initialised yet.

    Move the page script after jquery has loaded.

    
    
    

    For efficiency I recommend you do this in one of two ways:


    OPTION 1

    Use a master script file that loads after jquery.

    
    
    

    OPTION 2

    Use a placeholder template that will always load after jquery but can be initialised on individual pages.

    Master _Layout Page

    
    @RenderSection("Scripts", required: false)
    

    Content Page

    @section Scripts {
      
    }
    

提交回复
热议问题