1

I am trying to run jQuery code on elements contained within a jQuery tab which is not selected. If i quickly click the tab before the Ajax loading has completed it works, but if i leave it running without being selected the code will not be executed.

As ou can see below, the tab i want to load data into were not defined from the beginning, it was created when the user clicked a button.

The functionality i want to achieve is tabs, where the user will search for X in the start tab, then the new tab is created, content is loaded in the background (needs jQuery code for grids and format). Then the user can click the tab and see the results.

jQuery 1.10 jQuery-UI 1.10

Example:

<script>

$(document).ready(function(){

var myindex = 1;

$("#startsearch").click(function() {

    search = escape(($("#search").val()));

    searchdate = ($.datepicker.formatDate('yy-mm-dd', new Date()));

    var tabs = $( "#tabs" ).tabs();
    var ul = tabs.find( "ul" );

    // Add new tab
    newhtml = "<li id='henrik_tab_" + myindex + "Selector'><a href='#henrik_tab_" + myindex + "'>Search: " + searchdate + "</a></li>";
    newhtml2 = "<div id='henrik_tab_" + myindex + "'></div>";
    ul.append(newhtml);
    tabs.append(newhtml2);
    tabs.tabs( "refresh" );

    // Load data into tab
    $( "#henrik_tab_" + myindex).load("dosearch.php?data=" + search, function(responseTxt,statusTxt,xhr) {
            if(statusTxt=="success") {

        !! DOING STUFF WITH ELEMENTS CONTAINED IN THE NEW TAB HERE !!

            }
            if(statusTxt=="error")
                    alert("Error: "+xhr.status+": "+xhr.statusText);
    });

    // increse the counter for next tab
    myindex++;

});

$( "#tabs" ).tabs();

});
</script>

Any help would be much appreciated.

4

1 に答える 1

0

コードを変更してみる

tabs.append(newhtml2);

$( "#tabs" ).append(newhtml2);

修正されていない場合は、コードを実行する必要があることを示してください。

于 2013-07-07T13:54:49.107 に答える