在aspmenu项单击时调用jquery函数

本文关键字:调用 jquery 函数 单击 aspmenu | 更新日期: 2023-09-27 17:57:49

我在我的项目上有一个菜单项,在菜单项的子菜单上单击我想弹出一个div对话框。我的aspmenuitem在这里

<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
   <Items>
      <asp:MenuItem NavigateUrl="~/Cashbook/Parties.aspx" Text="Parties" />
      <asp:MenuItem NavigateUrl="~/Cashbook/Accounts.aspx" Text="Accounts" />
      <asp:MenuItem NavigateUrl="~/Cashbook/Funds.aspx" Text="Funds" />
      <asp:MenuItem NavigateUrl="~/Cashbook/FundTransfer.aspx" Text="Fund Transfer" />
      <asp:MenuItem NavigateUrl="~/Cashbook/Receipts.aspx" Text="Receipts" />
      <asp:MenuItem NavigateUrl="~/Cashbook/Payments.aspx" Text="Payments" />
      <asp:MenuItem NavigateUrl="~/Cashbook/AccountCategory.aspx" Text="Account Category" />
      <asp:MenuItem Text="Reports">
         <asp:MenuItem CssClass="sd" Text="Bank Reconcilation" />
         <asp:MenuItem Text="Anexure" />
         <asp:MenuItem Text="Statements" />
         <asp:MenuItem Text="Categorywise Statements" />
      </asp:MenuItem>
   </Items>
</asp:Menu>

在这里,我使用了cssclass,但它给了我运行时错误:"MenuItem没有名为‘cssclass’的公共属性"

请帮我解决这个问题提前感谢

在aspmenu项单击时调用jquery函数

如下所述更新菜单:

<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
    <LevelSubMenuStyles>
        <asp:submenustyle /> 
        <asp:submenustyle CssClass="sd"/> 
    </LevelSubMenuStyles>
    <Items>
        <asp:MenuItem NavigateUrl="~/Cashbook/Parties.aspx" Text="Parties" />
        <asp:MenuItem NavigateUrl="~/Cashbook/Accounts.aspx" Text="Accounts" />
        <asp:MenuItem NavigateUrl="~/Cashbook/Funds.aspx" Text="Funds" />
        <asp:MenuItem NavigateUrl="~/Cashbook/FundTransfer.aspx" Text="Fund Transfer" />
        <asp:MenuItem NavigateUrl="~/Cashbook/Receipts.aspx" Text="Receipts" />
        <asp:MenuItem NavigateUrl="~/Cashbook/Payments.aspx" Text="Payments" />
        <asp:MenuItem NavigateUrl="~/Cashbook/AccountCategory.aspx" Text="Account Category" />
        <asp:MenuItem Text="Reports">
            <asp:MenuItem  Text="Bank Reconcilation" />
            <asp:MenuItem Text="Anexure" />
            <asp:MenuItem Text="Statements" />
            <asp:MenuItem Text="Categorywise Statements" />
        </asp:MenuItem>
    </Items>
</asp:Menu>

然后为对话框添加DIV标签:

<div id="dialog" title="Contact form">
    <p>Hi, I am dialog</p>
</div>

然后点击子菜单,添加脚本进行初始化并显示对话框

<script type="text/javascript">
    // this initializes the dialog (and uses some common options that I do)
    $("#dialog").dialog({ autoOpen: false, modal: true, show: "blind", hide: "blind" });

    $('.sd').click(function () {
        $("#dialog").dialog("open");
        return false;
    });
</script>