Why can't radio buttons be “readonly”?

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

    JavaScript way - this worked for me.

    
    

    Reason:

    1. $('#YourTableId').find('*') -> this returns all the tags.

    2. $('#YourTableId').find('*').each(function () { $(this).attr("disabled", true); }); iterates over all objects captured in this and disable input tags.

    Analysis (Debugging):

    1. form:radiobutton is internally considered as an "input" tag.

    2. Like in the above function(), if you try printing document.write(this.tagName);

    3. Wherever, in tags it finds radio buttons, it returns an input tag.

    So, above code line can be more optimized for radio button tags, by replacing * with input: $('#YourTableId').find('input').each(function () { $(this).attr("disabled", true); });

提交回复
热议问题