Why can't radio buttons be “readonly”?

前端 未结 13 990
误落风尘
误落风尘 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:06

    I've faked readonly on a radio button by disabling only the un-checked radio buttons. It keeps the user from selecting a different value, and the checked value will always post on submit.

    Using jQuery to make readonly:

    $(':radio:not(:checked)').attr('disabled', true);
    

    This approach also worked for making a select list readonly, except that you'll need to disable each un-selected option.

提交回复
热议问题