[英]jQuery only seems to be working in Layout.cshtml
I am currently working on the basics of a .NET C# Razor page application running the following:我目前正在研究运行以下内容的 .NET C# Razor 页面应用程序的基础知识:
My current issue is that jQuery (and plain JS) are only working in the Layout.cshtml file, I have tried the following:我当前的问题是 jQuery(和普通 JS)仅在 Layout.cshtml 文件中工作,我尝试了以下操作:
At this stage I am fairly sure it is just a case of, it needs to be setup in a very particular way in .NET5, but I really have no more clues在这个阶段,我相当确定这只是一个案例,它需要在 .NET5 中以非常特殊的方式进行设置,但我真的没有更多线索
Bottom of _Layout.cshtml _Layout.cshtml 底部
</header>
<div class="container-fluid">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@RenderSection("Head", required: false);
@RenderSection("Scripts", required: false);
</body>
</html>
Bottom of the index.cshtml file index.cshtml 文件底部
@section scripts {
<script>
$(document).ready(function () {
$(".btn-reply").click(function (event) {
alert("it works");
});
});
</script>
}
令人沮丧的是,结果证明这根本与 JS 无关,实际上这归结于主 div,其中行类的 z-index 为 -1,不知道这是怎么回事,我不记得了已经设置了这个,但如果我这样做了,我会向所有花时间阅读本文的人道歉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.