以下是代码:
$(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 :(得分:0)
值得一试,但您是否尝试将$input.attr('checked', false);
替换为$input.removeAttr('checked');
?因为你还在设置它。
虽然我很困,所以我没有正确解析所有的代码,但是我看到了这个小东西..睡觉。