单选按钮和复选框

时间:2011-11-15 17:31:20

标签: jquery

是否可以选择单选按钮和复选框?

除以下方式外:

 $(':checkbox').live('change',function()
 {
       $(':radio').prop('checked',!$(this).prop('checked'));
 });

 $(':radio').live('change',function()
 {
       $(':checkbox').prop('checked',!$(this).prop('checked'));
 });

Here是一个可以解决的问题。

1 个答案:

答案 0 :(得分:1)

一行怎么样?

<强> HTML

<input type='checkbox'>
<input type='radio'>

<强> JS

 $(':checkbox,:radio').live('change',function()
 {
       $(this).siblings(':checkbox,:radio').prop('checked',!$(this).prop('checked'));
 });

JSFiddle上的现场演示here