2011-08-24 20 views
0

我正在構建一個顯示兩個問題的問題。爲什麼jQuery live('click')只能用於AJAX分頁的特定類的第一頁?

當我按下「MCQRadio」類的單選按鈕時,會觸發點擊處理程序,但它只能在第一頁上工作。 GridRadio的Clickhandler適用於所有頁面。

我在做什麼錯了?

這是代碼:

<script language="javascript"> 
    $(document).ready(function() 
    { 

     $(".page-number").live("click", function() 
     { 

      var page = parseInt($(this).html()); 
      var progressbarValue = ((page/$("#NumberOfPages").val()) * 100); 
      var catId = $("#CategoryID").val(); 

      $.ajax(
      { 
       url: '@Url.Action("QuestionList")', 
       data: { 
        "categoryId": catId, 
        "page": page 
       }, 
       success: function(data) 
       { 
        $("#question-list").html(data); 
        $("#progressbar").progressbar("value", progressbarValue); 
        $("#progresstext").html("<p>" + Math.round(progressbarValue) + "% gennemgået</p>"); 

       } 
      }); 
     }); 

     $('.MCQRadio').click(function() 
     { 

      var button = $(this); 
      var question_id = button.attr('question-id'); 
      var mcq_id = button.attr('mcq-id'); 

      $('#savingquestion').fadeIn(); 

      $.ajax(
      { 
       url: '/SaveSurveyAnswers/SaveMCQAnswer', 
       data: { 
        "mcq_id": mcq_id, 
        "question_id": question_id 
       }, 
       success: function(data) 
       { 
        button.parent().parent().attr('id', "answered"); 
        $('#savingquestion').fadeOut(); 
       } 
      }); 
     }); 

     $('.GridRadio').live('click', function() 
     { 

      var button = $(this); 

      var row_id = button.attr('row-id'); 
      var column_id = button.attr('column-id'); 
      var question_id = button.attr('question-id'); 

      $('#savingquestion').fadeIn(); 

      $.ajax(
      { 
       url: '/SaveSurveyAnswers/SaveGridAnswer', 
       data: { 
        "row_id": row_id, 
        "column_id": column_id, 
        "question_id": question_id 
       }, 
       success: function(data) 
       { 

        // Hvis ActionControlleren returnerer complete, betyder det at spørgsmålet er fuldt besvaret. 
        // Hvis dette er tilfældet, skal id på den omringende table og div ændres, således at der kommer 
        // de rigtige farver for besvarede spørgsmål 
        $('#savingquestion').fadeOut(); 

        if (data == "complete") 
        { 
         var table = button.closest('table'); 
         var div = button.closest('div'); 

         if (table.attr('id') != "answeredTable") 
         { 
          table.attr('id', 'answeredTable'); 
         } 
         if (div.attr('id') != "answered") 
         { 
          div.attr('id', 'answered'); 
         } 
        } 
       } 
      }); 

     }); 

    }); 

回答

0

功能爲MCQRadio是不是活的功能,只是一個正常的點擊功能。我猜測它也應該是一個live函數。

$('.MCQRadio').click(function() 

應該

$('.MCQRadio').live('click', function() 
+0

非常感謝。亞當泰爾森在你面前1分鐘回答,所以我必須回答他:/對不起。 – Nanek

+0

@Nanek我在他面前一分鐘回答。只是讓你知道 – nickmoriarty

+0

嗯它說16分鐘前在這裏,和他15分鐘前:/ – Nanek

1

也許是因爲一個使用實時和其他不?

變化:

$('.MCQRadio').click(function() ... 

要:

$('.MCQRadio').live('click', function() ... 
+0

Doh ...!謝謝 :) – Nanek

相關問題