Javascript - 点击处理程序 ignored/skipped

Javascript - On click handler ignored/skipped

我有以下代码:

$(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');
        }
    });

我都尝试过使用:

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

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

});

当我在其中任何一个中放置一个断点时,none 被击中。

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

为什么会这样?

$(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');    
    });
});

这是因为您没有禁用锚元素的默认行为。在单击事件上使用 event.preventDefault()

停止默认行为

像这样

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

因为它已经在 ready() 函数中,所以你不需要将它包装在另一个现成的函数中