2012-06-18 28 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); 

希望有所帮助!