我有5个按钮,用户可以检查。一会儿代码允许用户检查多于1个按钮。 我想,很快他们点击第二个按钮,出现警告对话框,看他们是否想要进行这个过程,如果是,它会将checked class
添加到选定的按钮。jquery只允许一个按钮被检查
<form class="table_book">
<input id="block_book" type="button" value="first" class="checked">
<input id="block_book" type="button" value="second">
<input id="block_book" type="button" value="third">
<input id="block_book" type="button" value="fourth">
<input id="block_book" type="button" value="fifth">
</form>
$("input#block_book").live('click',function(){
if($(".table_book #block_book").hasClass("checked").length > 1) {
if(var conf = confirm('Are you sure want to select the button?'))
// ajax process
} else {
// remove unchecked class
}
}
})
ID必须是相同的。如果你想让他们共享这样的类型,请使用'class'。 – Spudley 2011-04-28 14:32:42