2016-12-02 14 views
0

私はすべてのJavaスクリプトとjQueryファイルをインクルードするためにASPマスターページを使用しています。私が直面しています問題は、私は、メニュー項目をクリックするとOrderManagement.jsaspマスターページのJQueryとカスタムコードのシーケンス

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

の私のjQueryの関数が呼び出されないということです。

マスターファイルのコードは次のようになります。

<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

は、ファイルが含ま見ることができます:あなたは、あなたのページの下部にカスタムコードを置くことができ、またはより良いまだ、ちょうどready機能を使用できますか?すべてのコンソールエラー? – JanR

+0

バンドルを使用しています。バンドルにjQueryを登録してみてください –

+0

@JanRいいえ、ファイルはそこに表示されず、コンソールエラーもありません。 – Novice

答えて

0

あなたのjQueryファイルをうまく含んでいます。調整が必要なカスタムjsファイルです。あなたのハンドラをリンクするためのコードは、のメニュー項目が作成される前に、のhtml文書の上部で呼び出されています。それはまだ作成されていないので、あなたのハンドラは何もしません。の後に、あなたの関数を呼び出してハンドラをリンクする必要があります。あなたのメニュー項目がレンダリングされました。ページのソースを表示するとき

$(document).ready(function() { 
    $(".menu-item").click(function() { 
    window.alert("some text"); 
    }); 
}); 
関連する問題