为什么我不能进入我的$ document Ready功能

时间:2013-11-02 22:52:53

标签: javascript jquery modal-dialog

我正在尝试弹出一个模态,我知道这个代码有效,但由于某种原因,我的js要么没有加载要么没有进入$ document.ready。我有一个警报,我在调试模式下运行,它甚至没有开火。

这是我的.aspx,带有加载js的脚本

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RCC_ChgPassTester.aspx.cs" Inherits="Regal.Web._Tester.RCC.RCC_ChgPassTester" %>
<%@ Register Src="RCC_ChangePassword.ascx" TagPrefix="Rcc" TagName="RCCChgPass" %> 
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <link href="/assets/css/home.css" media="all" rel="stylesheet" type="text/css"/> 
    <link href="/assets/css/modal.css" media="all" rel="stylesheet" type="text/css"/>
    <link href="/assets/css/rcc-main.css" media="all" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" href="http://www.regmovies.com/assets/css/jquery-plugins.css"/>
 <!--   <link rel="stylesheet" href="/assets/css/global.css" /> -->  

    <script type="text/javascript" src="/assets/js/jquery.js"></script>
    <script type="text/javascript" src="/assets/js/jquery-plugins.js"></script>
    <script type="text/javascript" src="/assets/js/jquery.openCarousel.js"></script>
    <script type="text/javascript">
        /*<![CDATA[*/
        window.jQuery || document.write('<script type="text/javascript" src="/assets/js/jquery.js">\x3C/script>') /*]]>*/
    </script>
<script type="text/javascript" src="../_assets/js/RCCTester.js"></script>
</head>
<body id="body" style="background-image:url(http://www.regmovies.com/~/media/Images/Site%20Takeovers/wallpaper_cloudyNP.ashx);">


    <form id="form1" runat="server">
    <div>         
    <RCC:RCCChgPass runat="server" ID="ChgPass" />
    </div>
    </form>

</body>
</html>

这是我的剧本:

(function (window) {
    var
   $ = window.jQuery,
   modalLocation = '#modal-password-change',
    modalPasswordChangeOpts = {
        autoOpen: true,
        modal: true,
        resizable: false,
        draggable: false,
        width: '450',
        height: '550',
        dialogClass: 'modal',
        close: function () { $(this).dialog('destroy'); }
    };

    function showModal() {
        $(modalLocation).dialog($.extend(modalPasswordChangeOpts))
        $(modalLocation).dialog('open');
    }

    $(document).ready(function () {

        RCC.showModal();
        alert("I am here");
        return false;
    });


    window.RCC = window.RCC || {};
    window.RCC.showModal = showModal;
});

2 个答案:

答案 0 :(得分:3)

您已在闭包中定义了该函数,但从不调用它。试试这个:

(function (window) {
    // your code...
})(window);

答案 1 :(得分:2)

您正在定义一个永远不会被调用的函数。由于其他一切都依赖于此功能的运行,因此没有任何反应。

在定义函数后立即调用该函数以查看某些操作:

(function (window) {
    /// your code here
})(window); // added (window) to invoke