Javascript 如何赋予按钮组与单选按钮组相同的行为

Javascript 如何赋予按钮组与单选按钮组相同的行为,javascript,jquery,Javascript,Jquery,我想让我的按钮元素像单选按钮一样工作。我的意思是,如果我选择一个具有相同名称或id的,那么其他的将被取消选择 <button name="options" id="options>Button 1</button> <button name="options" id="options>Button 2</button> <button name="options" id="options>Button 3</button>

我想让我的
按钮
元素像单选按钮一样工作。我的意思是,如果我选择一个具有相同名称或id的,那么其他的将被取消选择

<button name="options" id="options>Button 1</button>
<button name="options" id="options>Button 2</button>
<button name="options" id="options>Button 3</button>
按钮2

我会将
id
更改为
class
,然后对于要作为一个组的每组按钮,都有一个唯一的类名。下面是两个按钮组的示例,我通过单击只剩下的一个按钮添加了重新启用按钮的功能

$('button')。在('click',function()上{
var name=$(this.attr('name');
var cl=$(this.attr('class');
var-reenable=false;
$('.+cl).each(function(){
if($(this.attr('name')!=name){
if($(this).attr('disabled')=='disabled')
可重入=真;
其他的
$(this.attr('disabled',true);
}
});
如果(可重入)
$('.+cl).attr('disabled',false);
});

按钮1
按钮2
按钮3

按钮1 按钮2
按钮3
id
在同一文档中应该是唯一的。您可以使用
class=“options”
而不是如何实现“选定”按钮元素?