Only one checkbox checked at a time in javascript

前端 未结 2 1976
说谎
说谎 2021-01-26 05:41

I have 3 checkbox, for which I want only 1 checkbox to be checked at a time. below is my fiddle for the html

JS fiddle

I want this to b

2条回答
  •  天命终不由人
    2021-01-26 06:00

    function selectOnlyThis(id) {
        for (var i = 1;i <= 4; i++)
        {
            document.getElementById(i).checked = false;
        }
        document.getElementById(id).checked = true;
    }
     Option 1
     Option 2
     Option 3
     Option 4

    It should help you

提交回复
热议问题