2013-11-02 100 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);