开发者

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

开发者 https://www.devze.com 2022-12-10 09:44 出处:网络
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 retr

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

精彩评论

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