HTML checkbox - allow to check only one checkbox

前端 未结 5 1892
花落未央
花落未央 2021-01-19 14:07

I have some checkboxes in each row in my table. Each one checkbox has name=\'myName\' because I want to select only one checkbox in each row. But something I\'m

5条回答
  •  执念已碎
    2021-01-19 14:29

    $('#OvernightOnshore').click(function () {
        if ($('#OvernightOnshore').prop("checked") == true) {
            if ($('#OvernightOffshore').prop("checked") == true) {
                $('#OvernightOffshore').attr('checked', false)
            }
        }
    })
    
    $('#OvernightOffshore').click(function () {
        if ($('#OvernightOffshore').prop("checked") == true) {
            if ($('#OvernightOnshore').prop("checked") == true) {
                $('#OvernightOnshore').attr('checked', false);
            }
        }
    })
    

    This above code snippet will allow you to use checkboxes over radio buttons, but have the same functionality of radio buttons where you can only have one selected.

提交回复
热议问题