开发者

Can I select only one checkbox out of multiple checkboxes using jquery?

I need to allow the user to check only one checkbox out of mor开发者_JAVA技巧e than five checkboxes. The checkboxes are having the same name and different values. I need to store these values and retrieve from database. Does Jquery support this feature? I am a newbie...


Better to use radio buttons in this case. They are meant to serve this purpose. Selecting only an item from this case.

If checkbox is a strict requirement then you can do this with jQuery. You have to unselect all the checboxes first and then check the one which is clicked.


use radiobuttons.

http://www.w3schools.com/html/html_forms.asp --> scroll down to Radio Buttons


When you dont wont radio buttons here is a jquery solution:

var checkboxes = $(':checkbox.myCheckboxGroup');
checkboxes.click(function(){
  var self = this;
  checkboxes.each(function(){
    if(this!=self) this.checked = ''
  })
})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜