2016-12-02 39 views
0

我正在使用ASP主頁來包含所有的java腳本和jQuery文件。我現在面臨的問題是,在OrderManagement.jsjQuery和自定義代碼在asp主頁中的順序

$(".menu-item").click(function() { 
    window.alert("some text"); 
}); 

我jQuery的功能,當我點擊菜單項不會被調用。

我在Master文件中的代碼如下所示。

<html lang="en"> 
<head runat="server"> 
    <meta charset="utf-8" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 
    <title><%: Page.Title %> My Website</title> 

    <asp:PlaceHolder runat="server"> 
     <%: Scripts.Render("~/bundles/modernizr") %> 
    </asp:PlaceHolder> 
    <webopt:BundleReference runat="server" Path="~/Content/css" /> 
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> 
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> 
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Oswald:400,700,300"> 
</head> 
<body> 
    <form runat="server"> 
     <asp:ScriptManager runat="server"> 
      <Scripts> 
       <%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%> 
       <%--Framework Scripts--%> 
       <asp:ScriptReference Name="MsAjaxBundle" /> 
       <asp:ScriptReference Name="jquery" /> 
       <asp:ScriptReference Name="bootstrap" /> 
       <asp:ScriptReference Name="respond" /> 
       <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" /> 
       <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" /> 
       <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" /> 
       <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" /> 
       <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" /> 
       <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" /> 
       <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" /> 
       <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" /> 
       <asp:ScriptReference Name="WebFormsBundle" /> 
       <%--Site Scripts--%> 
      </Scripts> 
     </asp:ScriptManager> 
    <script src="Scripts/OrderManagement.js"></script> 

我不確定在哪裏把我的jQuery文件,以便它的工作。

+0

你可以看到包含的文件,當您查看該頁面的源代碼?任何控制檯錯誤? – JanR

+0

您正在使用包。嘗試在包中註冊jQuery –

+0

@JanR不,該文件沒有顯示在那裏,並且沒有控制檯錯誤。 – Novice

回答

0

你正在包括你的jQuery文件就好了。這是您需要調整的自定義js文件。連接你的處理程序的代碼在你的html文檔的頂部被調用,你的菜單項被創建之前。而且由於它還沒有創建,你的處理程序就毫無用處。你需要調用你的函數,在你的菜單項已經渲染後,鏈接你的處理器。你可以把自定義代碼在你的頁面的底部,或者更好,只需使用ready功能:

$(document).ready(function() { 
    $(".menu-item").click(function() { 
    window.alert("some text"); 
    }); 
});