2013-11-02 101 views
1

我想弹出一个模式,我知道这个代码的作品,但由于某种原因,我的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; 
}); 
+0

控制台抛出的任何错误?它不应该只是'showModal()'而不是RCC.showModal() – charlietfl

+0

什么是'window.jQuery || document.write(...'code for?我知道类似的代码有时用于人们从CDN中包含jQuery,他们在那里测试包含是否工作,如果不使用本地副本,但您使用的是相同的代码作为原始路径包括...(你正在做它_after_包括依赖于jQuery已经在那里的插件) – nnnnnn

回答

2

你一定有一个永远不会被调用的函数。由于一切都依赖于这个函数的运行,所以没有任何反应。

调用函数定义它看到一些行动后立即:

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

好的赶上.... – Niklas

+0

哇...谢谢大家,我会修复它应该工作我是新来的使用js,所以我仍然站立起来,最好的问候, –

3

您已经定义了闭包内的功能,但从来没有把它。试试这个:

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