我有一个表单设置,所以当你选择一个复选框时,相关的UL将展开显示更多选项的基础上的选择。它的工作原理,但只有当用户点击复选框的标签。如果点击该复选框,UL会按预期展开,但该框不会被检查。jQuery复选框没有检查
的Javascript:
jQuery(document).ready(function()
{
jQuery('.toggleUL').click(function()
{
var checkbox = jQuery(this).find('input');
var ul = jQuery(this).next('ul');
if (ul.css('display') == 'block') { ul.find('input').attr('checked', false); }
if (checkbox.attr('checked') == false)
{
checkbox.attr('checked', true);
}
else
{
checkbox.attr('checked', false);
}
ul.slideToggle('slow'); return false;
});
});
HTML:
<label class="toggleUL"><input style="margin-right: 10px" type="checkbox" name="quoteWebsite" id="quoteWebsite" value="xxx" />xxx</label>
<ul style="list-style-type: none; display: none">
<li style="margin-left: 20px"><label><input style="margin-right: 10px" type="checkbox" name="quoteWebsite1[]" id="quoteWebsite1" value="xxx" />xxx</label></li>
<li style="margin-left: 20px"><label><input style="margin-right: 10px" type="checkbox" name="quoteWebsite1[]" id="quoteWebsite2" value="xxx" />xxx</label></li>
<li style="margin-left: 20px"><label><input style="margin-right: 10px" type="checkbox" name="quoteWebsite1[]" id="quoteWebsite3" value="xxx" />xxx</label></li>
</ul>
的的slideToggle()函数不工作应该的方式。当盒子/标签被点击时,UL会立即展开然后收回。我可以停止的唯一方法是添加'返回false';这当然会导致复选框无法检查。因此checkbox.attr()。
破解了代码,我知道。但是我怎样才能让复选框起作用? >。 <
停止了复选框检查。不是当点击它本身或它的标签。 – spirax 2009-11-06 07:44:34