2016-09-16 68 views
0

我有下面的代码:使用Javascript - 在点击处理忽略/跳过

$(document).on('click','#tab-personal',function(e){ 
loadit('personal');  
}); 

$("#tab-personal").click(function() 
{ 

}); 

,当我:

$(document).ready(function(){ 
     var rebuild = getParameterByName("rebuild"); 

     var createdStructures = $('#AtoZContentDiv').children().length; 


     if ((rebuild !== undefined && rebuild !== null && rebuild.indexOf("true") === 0) || (createdStructures === 0)) 
     { 
      // clean up pre-existing data 
      cleanUp(); 


      // create container structure 
      createFormLinkContainers(); 

      // Call SP web services to retrieve the information and create the A to Z 
      retrieveListData(); 

      completeInitialization(); 
     } 
     else 
     { 
      aggregateAll = jQuery.parseJSON($('#hdnAggregateAll').val()); 
      aggregatePersonal = jQuery.parseJSON($('#hdnAggregatePersonal').val()); 
      aggregateBusiness = jQuery.parseJSON($('#hdnAggregateBusiness').val()); 
      ministryAggregate = jQuery.parseJSON($('#hdnMinistryAggregate').val()); 
      caAggregate = jQuery.parseJSON($('#hdnCAAggregate').val()); 
      sTaxAggregate = jQuery.parseJSON($('#hdnSTaxAggregate').val()); 
      bTaxAggregate = jQuery.parseJSON($('#hdnBTaxAggregate').val()); 
      leTaxAggregate = jQuery.parseJSON($('#hdnLETaxAggregate').val()); 

      var type = getParameterByName("filter"); 

     $("#tab-all").click(function() 
     { 
       loadit('all'); 
     });   


     $("#tab-business").click(function() 
     { 
      loadit('business'); 
     }); 

     $("#tab-personal").click(function() 
     { 

     }); 


     $(document).on('click','#tab-personal',function(e){ 
     loadit('personal');  
     }); 


       buildFilterMenu(); 
       loadit('all'); 
     } 
    }); 

我一直在使用这两种尝试在他们中间放置一个断点,没有一个被击中。

HTML:

<div id="tabs" style="display: inline-block;"> 
    <ul><li><a class="selected" id="tab-all" href="#" type="all"><b>All Forms</b></a></li> 
    <li><a id="tab-business" href="#" type="business"><b>Business</b> </a></li> 
    <li><a id="tab-personal" href="#" type="personal"><b>Personal</b> </a></li></ul> 
</div> 

全码:http://pastebin.com/vzLPX3cU

这究竟是为什么?

+0

你尝试执行添加听众在控制台?试试这个:$(“#tab-personal”).on(“click”,function(){console.log(“click!”); }); – Sabik

+0

我在Chrome的开发人员工具调试器中放置了一个断点。我曾尝试把一个console.log('<<<<个人'),但代码没有被击中。 – Brian

+0

与你的例子DOM作品https://jsfiddle.net/k06w4mos/。也许你有一些错误,你的代码不能完全执行? – Sabik

回答

0
$(document).ready(function(){ 
    var rebuild = getParameterByName("rebuild"); 
    var createdStructures = $('#AtoZContentDiv').children().length; 
    if ((rebuild !== undefined && rebuild !== null && rebuild.indexOf("true") === 0) || (createdStructures === 0)){ 
     // clean up pre-existing data 
     cleanUp(); 

     // create container structure 
     createFormLinkContainers(); 

     // Call SP web services to retrieve the information and create the A to Z 
     retrieveListData(); 
     completeInitialization(); 
    }else{ 
     aggregateAll = jQuery.parseJSON($('#hdnAggregateAll').val()); 
     aggregatePersonal = jQuery.parseJSON($('#hdnAggregatePersonal').val()); 
     aggregateBusiness = jQuery.parseJSON($('#hdnAggregateBusiness').val()); 
     ministryAggregate = jQuery.parseJSON($('#hdnMinistryAggregate').val()); 
     caAggregate = jQuery.parseJSON($('#hdnCAAggregate').val()); 
     sTaxAggregate = jQuery.parseJSON($('#hdnSTaxAggregate').val()); 
     bTaxAggregate = jQuery.parseJSON($('#hdnBTaxAggregate').val()); 
     leTaxAggregate = jQuery.parseJSON($('#hdnLETaxAggregate').val()); 

     var type = getParameterByName("filter"); 
      buildFilterMenu(); 
      loadit('all'); 
    } 
    $("#tab-all").click(function(){ 
      loadit('all'); 
    });   

    $("#tab-business").click(function(){ 
     loadit('business'); 
    }); 

    $(document).on('click','#tab-personal',function(e){ 
     loadit('personal');  
    }); 
}); 
+0

单独的$(document).ready()你的意思是?因为代码已经是这样了。 – Brian

+0

是的,点击事件应该在'$(document).ready()'函数内。并确保你已经包含Jquery库。 – Samir

+0

我不理解您对代码所做的更改。你能否详细说明一下? – Brian

0

这是因为您没有禁用锚元素的默认行为。在点击事件停止默认行为与event.preventDefault()

像这样

$("#tab-personal").click(function(event){ 
    event.preventDefault(); # this will prevent the default behavior 
    # do something 
}); 

,因为它已经是里面ready()功能,你不必在一个多准备功能包裹它

+0

不幸的是,这并没有工作 – Brian

+0

你使用的是jQuery选项卡吗? – Bhadra

+0

不,使用HTML和CSS的自定义选项卡。 – Brian