1

jQuery API を使用してタブを作成し、次のコードを使用して 2 番目のタブのクリック時に 1 つのイベント ハンドラーをバインドしました。

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

    });

アイデアはありますか?

4

2 に答える 2

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);
            });         
}

今、私は私が望む結果を得ています。

于 2012-06-19T03:47:14.900 に答える
0

ajax のロード後に選択されるタブ (この場合は 2 番目のタブ) を呼び出そうとしているようです。これを ajax 呼び出しで使用しないのはなぜですか?

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

それが役立つことを願っています!

于 2012-06-18T20:05:14.450 に答える