0

我在使用“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");
          });

      });

  });
4

1 回答 1

0

尝试使用.live()方法绑定点击事件。This demo可能会帮助你。

于 2010-11-30T06:00:33.500 回答