Why can't radio buttons be “readonly”?

前端 未结 13 970
误落风尘
误落风尘 2020-11-27 10:45

I would like to show a radio button, have its value submitted, but depending on the circumstances, have it not editable. Disabled doesn\'t work, because it doesn\'t submit t

相关标签:
13条回答
  • 2020-11-27 11:17

    I'm using a JS plugin that styles checkbox/radio input elements and used the following jQuery to establish a 'readonly state' where the underlying value is still posted but the input element appears inaccessible to the user, which is I believe the intended reason we would use a readonly input attribute...

    if ($(node).prop('readonly')) {
        $(node).parent('div').addClass('disabled'); // just styling, appears greyed out
        $(node).on('click', function (e) {
            e.preventDefault();
        });
    }
    
    0 讨论(0)
提交回复
热议问题