2010-08-04 34 views
0

這裏的,剝離下來,代碼:需要一些幫助,我的jQuery的輸入斯泰勒

$(document).ready(function() 
{ 
    var $input = $('input[type="checkbox"]'); 

    $input.wrap('<div class="stylecheck-container" style="display: inline" />').addClass('stylecheck').hide(); 
    $container = $input.parent('div.stylecheck-container'); 

    if ($container.parent('label').length > 0) 
    { 
     $container.append($container.parent('label').text() + ' '); 
     $container.parent('label').replaceWith($container); 
    } 

    $input.change(function() 
    { 
     alert(1); 
    }); 

    $container.click(function() 
    { 
     if ($input.is(':checkbox')) 
     { 
     if ($input.is(':checked')) 
      $input.attr('checked', true); 
     else 
      $input.attr('checked', false); 
     } 
    }); 
}); 

我遇到的問題是,當我嘗試刪除父標籤,變化不再被檢測到。

如果我註釋掉第6行if語句,它可以正常工作。

這是怎麼回事?

回答

0

值得一試,但您是否試過用$input.removeAttr('checked');替換$input.attr('checked', false);?因爲你還在設置它。

雖然我很困,所以我沒有正確解析所有的代碼,但我看到這個小東西..睡覺。

+0

剛剛嘗試過它 - 沒有解決它。我看不出爲什麼刪除標籤會導致代碼失敗:/ – dave 2010-08-04 07:09:46