简体   繁体   English

如何在asp:菜单项上添加客户端事件

[英]How to add client side event on asp:menu item click

I am using <asp:Menu> control in my web site and populated it from my Sql Server database table using XML data source. 我在网站中使用<asp:Menu>控件,并使用XML数据源从Sql Server数据库表中填充了该控件。 Now i want to add a client side event on menu item click. 现在,我想在菜单项单击上添加一个客户端事件。 When a user clicks any menu item i need to show a please wait dialog window until the page got complete refreshed. 当用户单击任何菜单项时,我需要显示一个请稍候的对话框,直到页面完全刷新为止。 For that i need to run my java script function on client click. 为此,我需要在客户端单击上运行我的Java脚本函数。 So can any one tell me how to add a client side click event on menu item click. 因此,谁能告诉我如何在菜单项单击上添加客户端单击事件。

Problem is solved by adding css classes 通过添加CSS类解决了问题

<DynamicMenuStyle CssClass="primaryDynamicMenu" />
<StaticMenuStyle CssClass="primaryStaticMenu"/>

And then add this jquery function for main-menu items: 然后为主菜单项添加此jquery函数:

$(function() {
    $(".primaryStaticMenu a").each(function(index) {
        $(this).click(function() {
            alert($(this).attr("href"));
        });
    });
});

For sub-menu items: 对于子菜单项:

$(function() {
    $(".primaryDynamicMenu a").each(function(index) {
        $(this).click(function() {
            alert($(this).attr("href"));
        });
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM