2012-06-18 29 views
1
動態調用select事件

我已經使用jQuery API創建標籤,並通過使用下面的代碼綁定在第二個選項卡中單擊一個事件處理程序:無法在標籤在jQuery的

$('#tabs').bind('tabsselect', function(event, ui) { 
     refreshRemoveUI(event,ui); 
    }); 

function refreshRemoveUI(event,ui) { 
    if(ui.index==1){ 
     $.get('FrontServlet?operation=getAllQues',function(data) { 
      var html = ""; 
      var questionsNum = data.split(","); 
      if(questionsNum!="") { 
       html += '<br/><input type=checkbox name=removeAllQuestionId id=removeAllQuestionId onclick="toggleAll(this.checked)"/> Select/Deselect All<br/>'; 
       for(var i=0;i<questionsNum.length;i++){ 
        html += '<br/><input type=checkbox name=removeQuestionId id=removeQuestionId /> ' + questionsNum[i]; 
       } 
       $('#remove').show(); 
      } else { 
       $('#remove').hide(); 
       html = 'No question available in quiz'; 
      } 
      $('#removequestions').html(html); 
      });   
    } 
} 

我想要調用關於Ajax請求的完成也並按照相同的綁定事件是什麼,我都試過,但沒有運氣:

$.get('FrontServlet?operation=remove&position='+val, function(data) { 
     $("#tabs li.ui-state-default:nth(1)").trigger("select"); 

    }); 

任何想法的傢伙?

+0

只是在這裏做一些猜測,因爲我不完全知道這件事,沒有一個工作樣本,它是一個重現問題的大量工作,但不應該''..]。trigger('tabselect ')'而不是'[..]。trigger('select')'? – Jasper

回答

0

沒有建議似乎工作 我不得不重構下面我的代碼:

$('#tabs').bind('tabsselect', function(event, ui) { 
     if(ui.index==1){ 
      refreshRemoveUI(event,ui); 
     } 

    }); 

      $.get('FrontServlet?operation=remove&position='+val, function(data) { 
       refreshRemoveUI(); 

      }); 

function refreshRemoveUI(event,ui) { 
     $.get('FrontServlet?operation=getAllQues',function(data) { 
      var html = ""; 
      var questionsNum = data.split(","); 
      if(questionsNum!="") { 
       html += '<br/><input type=checkbox name=removeAllQuestionId id=removeAllQuestionId onclick="toggleAll(this.checked)"/> Select/Deselect All<br/>'; 
       for(var i=0;i<questionsNum.length;i++){ 
        html += '<br/><input type=checkbox name=removeQuestionId id=removeQuestionId /> ' + questionsNum[i]; 
       } 
       $('#remove').show(); 
      } else { 
       $('#remove').hide(); 
       html = 'No question available in quiz'; 
      } 
      $('#removequestions').html(html); 
      });   
} 

現在我得到我想要的結果。

0

看起來你試圖調用選項卡(在這種情況下的第二個選項卡)在ajax加載後被選中。你爲什麼不在你的ajax調用中使用它?

$('#tabs').tabs("select", 1); 

希望有所幫助!