简体   繁体   English

ASP.net(Document).ready()无法运行

[英]ASP.net (Document).ready() failing to run

I have an ASP.net MVC 4 web application (Visual Basic). 我有一个ASP.net MVC 4 Web应用程序(Visual Basic)。 On the _Layout.vbhtml shared view I have a small bit of javascript at the very bottom of the code designed to hide a loading div and display the main page content once everything has loaded. 在_Layout.vbhtml共享视图上,我在代码的最底部有一小段javascript,旨在隐藏加载div并在加载完所有内容后显示主页内容。

Here is part of the .vbhtml file: 这是.vbhtml文件的一部分:

        <!-- JQuery & Javascript Loading -->
        @Scripts.Render("~/bundles/jquery", "~/bundles/jquerymain", "~/bundles/bootstrap", "~/bundles/lib", "~/bundles/gebo_dashboard")
        @RenderSection("scripts", required:=False)

        <!-- Close loading page -->
        <script type="text/javascript">
            $(document).ready(function () {
                //* show all elements & remove preloader
                alert("Hello Ready");
                setTimeout('$("html").removeClass("js")', 1000);
            });
        </script>
    </div>
</body>

And here is the produced html: 这是产生的html:

        <!-- JQuery & Javascript Loading -->
        <script src="/Scripts/jquery-1.7.1.js"></script>
        <script src="/Scripts/jquery/jquery.ui.touch-punch.js"></script>
        <script src="/Scripts/jquery/jquery.ui.totop.js"></script>
        <script src="/Scripts/jquery/jquery.easing.1.3.js"></script>
        <script src="/Scripts/jquery/jquery.debouncedresize.js"></script>
        <script src="/Scripts/jquery/jquery.cookie.js"></script>
        <script src="/Scripts/jquery/jquery.qtip.js"></script>
        <script src="/Scripts/jquery/jquery.colorbox.js"></script>
        <script src="/Scripts/jquery/jquery.jBreadCrumb.1.1.js"></script>
        <script src="/Scripts/jquery/jquery.actual.js"></script>
        <script src="/Scripts/jquery/jquery.imagesloaded.js"></script>
        <script src="/Scripts/jquery/jquery.wookmark.js"></script>
        <script src="/Scripts/jquery/jquery.mediaTable.js"></script>
        <script src="/Scripts/jquery/jquery.peity.js"></script>
        <script src="/Scripts/jquery/jquery.flot.js"></script>
        <script src="/Scripts/jquery/jquery.flot.pie.js"></script>
        <script src="/Scripts/jquery/jquery.flot.resize.js"></script>
        <script src="/Scripts/bootstrap/bootstrap.js"></script>
        <script src="/Scripts/bootstrap/bootstrap.plugins.js"></script>
        <script src="/Scripts/lib/jquery-mousewheel.js"></script>
        <script src="/Scripts/lib/antiscroll.js"></script>
        <script src="/Scripts/lib/fullcalendar.js"></script>
        <script src="/Scripts/lib/ios-orientationchange-fix.js"></script>
        <script src="/Scripts/lib/list.js"></script>
        <script src="/Scripts/lib/list.paging.js"></script>
        <script src="/Scripts/lib/prettify.js"></script>
        <script src="/Scripts/lib/sticky.js"></script>
        <script src="/Scripts/gebo/gebo_common.js"></script>
        <script src="/Scripts/gebo/gebo_dashboard.js"></script>

        <!-- Close loading page -->
        <script type="text/javascript">
            $(document).ready(function () {
                //* show all elements & remove preloader
                alert("Hello Ready");
                setTimeout('$("html").removeClass("js")', 1000);
            });
        </script>
    </div>
</body>

When I load up the page and view it in a browser, the $(document).ready function never fires and so leaves the loading div visible. 当我加载页面并在浏览器中查看时,$(document).ready函数从不触发,因此使加载div可见。

I have tested the script section by placing an alert outside of the $(document).ready function, both before and after and the alerts fire of exactly the way I'd expect them to. 我已经通过在$(document).ready函数之前和之后放置一个警报来测试脚本部分,并且警报完全按照我期望的方式触发。 However the alert inside of the $(document).ready function never shows, indicating that the function never runs. 但是,$(document).ready函数内部的警报永远不会显示,表明该函数永远不会运行。

I have also tried using the pageLoad() function with no luck too. 我也尝试过使用pageLoad()函数,但也没有运气。

Does anyone know why this refuses to work? 有谁知道为什么这拒绝工作?

Ah, i've just found the issue. 啊,我刚发现问题。 I've been porting a template into my ASP.net project and there was a single javascript error on the page according to Firebug. 我一直在将模板移植到我的ASP.net项目中,根据Firebug,页面上只有一个javascript错误。 Not sure how I missed it, but solving the error has fixed the issue. 不知道我是怎么错过的,但是解决错误已解决了该问题。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM