Values of disabled inputs will not be submitted

前端 未结 7 2336

This is what I found by Firebug in Firefox.

Is it the same in other browsers?

If so, what\'s the reason for this?

7条回答
  •  甜味超标
    2020-11-22 06:10

    There are two attributes, namely readonly and disabled, that can make a semi-read-only input. But there is a tiny difference between them.

    
    
    
    • The readonly attribute makes your input text disabled, and users are not able to change it anymore.
    • Not only will the disabled attribute make your input-text disabled(unchangeable) but also cannot it be submitted.

    jQuery approach (1):

    $("#inputID").prop("readonly", true);
    $("#inputID").prop("disabled", true);
    

    jQuery approach (2):

    $("#inputID").attr("readonly","readonly");
    $("#inputID").attr("disabled", "disabled");
    

    JavaScript approach:

    document.getElementById("inputID").readOnly = true;
    document.getElementById("inputID").disabled = true;
    

    PS disabled and readonly are standard html attributes. prop introduced with jQuery 1.6.

提交回复
热议问题