How can I make an entire HTML form “readonly”?

前端 未结 12 1453
无人及你
无人及你 2020-12-02 07:56

I have two pages with HTML forms. The first page has a submission form, and the second page has an acknowledgement form. The first form offers a choice of many controls, whi

12条回答
  •  被撕碎了的回忆
    2020-12-02 08:20

    This is an ideal solution for disabling all inputs, textareas, selects and buttons in a specified element.

    For jQuery 1.6 and above:

    // To fully disable elements
    $('#myForm :input').prop('disabled', true); 
    

    Or

    // To make elements readonly
    $('#myForm :input').prop('readonly', true); 
    

    jQuery 1.5 and below:

    $('#myForm :input').prop('disabled', 'disabled');
    

    And

    $('#myForm :input').prop('readonly', 'readonly');
    

提交回复
热议问题