jQuery click事件触发两次,页面有多个母版页

时间:2017-06-27 23:33:15

标签: jquery asp.net click master-pages

我有一个包含嵌套母版页的页面。两次触发的控件位于Master Master Page(BasicContentMaster)以及jquery click事件函数上。如何防止两次触发控件的click事件?

继承两个母版页的页面(首先继承LandingPageMaster),

<%@ Page Title="" Language="vb" AutoEventWireup="false" 
MasterPageFile="~/landingpages/LandingPageMaster.master" CodeBehind="Components.aspx.vb" Inherits="WebsiteProject.Components" %>

然后LandingPageMaster继承BasicContentMaster页面

<%@ Master Language="VB" MasterPageFile="~/BasicContent.Master" AutoEventWireup="false" CodeBehind="LandingPageMaster.master.vb" Inherits="WebSiteProject.LandingPageMaster" %>

在BasicContentMaster中,是从组件页面

单击时触发两次的控件
<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="BasicContent.master.vb" Inherits="WebSiteProject.BasicContent" %> 

<img id="m-navigation-img" src="/images/nav_menu.png" />

jquery点击功能

$('#m-navigation-img').click(function () {
  $('#m-navigation').slideToggle();
});

1 个答案:

答案 0 :(得分:1)

试试这个:

$('#m-navigation-img').unbind('click').bind('click', function () {
$('#m-navigation').slideToggle();
});