ASP.NET Core Web(MVC) 在 View 中 Jquery 无法使用

需在View中加上@section Scripts

@section Scripts{
    <script src="~/js/homeindex.js"></script>
}
https://ithelp.ithome.com.tw/upload/images/20230723/20113319GeuK851ojB.png

如果没有加上这指令的话,他会直接写入在@RenderBody()内,导致JQuery还未加载就先加载homeindex.js,故无法使用JQuery
https://ithelp.ithome.com.tw/upload/images/20230723/20113319kJMFpooOE4.png

以下用Chrome F12查看
未加上@section Scripts
https://ithelp.ithome.com.tw/upload/images/20230723/20113319lj1AYaI0g6.png

加上@section Scripts
https://ithelp.ithome.com.tw/upload/images/20230723/20113319LYKtDImhGu.png

(0)

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注