2010-08-04 31 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