2013-07-07 2 views
1

선택되지 않은 jQuery 탭에 포함 된 요소에서 jQuery 코드를 실행하려고합니다. Ajax 로딩이 완료되기 전에 탭을 빨리 누르면, 코드를 선택하지 않고 실행하면 코드가 실행되지 않습니다.선택되지 않은 jQuery-UI 탭에서 jQuery 코드를 실행하십시오. - 1.10

아래에서 볼 수 있듯이 데이터를로드하려는 탭은 처음부터 정의되지 않았으며 사용자가 버튼을 클릭 할 때 만들어졌습니다.

내가 원하는 기능은 탭입니다. 사용자가 시작 탭에서 X를 검색 한 다음 새 탭이 만들어지고 콘텐츠가 백그라운드에서로드됩니다 (그리드 및 형식의 jQuery 코드가 필요함). 그런 다음 사용자가 탭을 클릭하고 결과를 볼 수 있습니다.

jQuery를 1.10 jQuery를-UI 1.10

예 : 어떤 도움이 많이 주시면 감사하겠습니다

<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> 

.

답변

0

보십시오 변화 코드

tabs.append(newhtml2); 

가 해결되지 않으면

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

에, 코드가 실행하지만해야 보여 싶습니다.

+0

문제가 해결되었습니다. 스파크 라인을 사용하고 있었고 lib에 숨겨진 요소가 있는지 확인하는 체크가있었습니다. 그 탭에없는 요소는 물론 숨겨져 있습니다. – Henrik