سؤال

أواجه مشكلة في "Toggleclass". ما يفعله هذا البرنامج النصي هو أنه يضيف مجموعة جديدة من الحقل اعتمادًا على قيمة أزرار الراديو. يوجد داخل الحقل div جديد مخفي بشكل افتراضي وسيتم عرضه فقط إذا تم تشغيل "A" بواسطة حدث نقرة. في البداية ، يعمل ولكن بمجرد النقر على زر راديو آخر أو في نفس زر الراديو ، لا تعمل "ToggleClass" بعد الآن.

هنا هو الرمز:

$(document).ready(function(){

      $('.duplicatorRadio').click(function() {
          var this_index_limit = parseInt($(this).val());
          for(var i = 0; i < this_index_limit; i++) {
             if(!$('#text_box_' + i).length) {
                var headerValue = parseInt(i) + 1;
                $(
                  '<fieldset id="text_box_' + i + '"> <h3>Property ' + headerValue +' Information</h3> <a class="borrowerToggler" href="#">Show Co-Borrower</a> <div class="borrower hide"> <h5>Co-Borrower Information</h5></div></fieldset>'
                  ).appendTo($(this).parent());
             }
             else if($('#text_box_' + i).css('display') == 'none') {
                $('#text_box_' + i).show();
             }
          }

          $('fieldset').each(function() {
             var split_id = $(this).attr('id').split('_');
             if(!split_id.length) return;
             var index = parseInt(split_id[2]);
             if(index >= this_index_limit) {
                 $(this).hide();
             }
          });

          $("a.borrowerToggler").click(function(){
            $(this).next("div").toggleClass("hide");
          });

      });

  });
هل كانت مفيدة؟

المحلول

حاول باستخدام .live() طريقة لربط الحدث النقر. This demo قد HLP لك.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top