Tag: 收音机

jQuery检查/取消选中单选button

我有这个代码来检查/取消选中一个单选button。 我知道这是不好的用户界面,但我需要这个。 $('#radioinstant').click(function() { var checked = $(this).attr('checked', true); if(checked){ $(this).attr('checked', false); } else{ $(this).attr('checked', true); } }); 上述function不起作用。 如果我点击button,没有任何改变。 它仍然被检查。 为什么? 错误在哪里? 我不是一个jQuery专家。 我在jQuery 1.3.2 只是要清楚#radioinstant是单选button的ID。