$(文件)。就绪没有下MVC4项目工作 [英] $(document).ready doesn't work under MVC4 project

查看:106
本文介绍了$(文件)。就绪没有下MVC4项目工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是插入

$(document).ready(function () {
    alert("!!!");
});

因为通常到

@{
    ViewBag.Title = "Sign Up";
    Layout = "~/Views/Shared/_WebSite.cshtml";
}

<script type="text/JavaScript">

    $(document).ready(function () {
        alert("!!!");
    });

</script>

<h2>Sign Up</h2>

@using (Html.BeginForm())
{
    @Html.ValidationSummary()
{

}

}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

但我看不到警告()消息...

but I cannot see alert() message...

其他的事情的jQuery 工作正常,在此页......

other things of jQuery are working fine at this page...

做什么我失踪?

任何线索?

感谢您!

推荐答案

您可以看到jQuery是后您的code引用,如果你检查HTML。

You can see jQuery is referenced after your code if you inspect the html.

默认的项目还附带了会后的布局jQuery的参考呈现一个可选的脚本部分,这就是你的code应该去。

Default project comes with an optional scripts section that will be rendered after jQuery reference in the layout, that's where your code should go.

@{
    ViewBag.Title = "Sign Up";
    Layout = "~/Views/Shared/_WebSite.cshtml";
}



<h2>Sign Up</h2>

@using (Html.BeginForm())
{
    @Html.ValidationSummary()
{

}

}

@section Scripts {
    <script type="text/JavaScript">

    $(document).ready(function () {
        alert("!!!");
    });

    </script>
}

这篇关于$(文件)。就绪没有下MVC4项目工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆