How to make a dropdown readonly using jquery?

后端 未结 21 1156
终归单人心
终归单人心 2020-12-02 06:54

I am using the following statement to make it readonly but it is not working.

$(\'#cf_1268591\').attr(\"readonly\", \"readonly\"); 

I don\

21条回答
  •  暖寄归人
    2020-12-02 07:23

    I'd make the field disabled. Then, when the form submits, make it not disabled. In my opinion, this is easier than having to deal with hidden fields.

    //disable the field
    $("#myFieldID").prop( "disabled", true );           
    
    //right before the form submits, we re-enable the fields, to make them submit.
    $( "#myFormID" ).submit(function( event ) {
        $("#myFieldID").prop( "disabled", false );
    });     
    

提交回复
热议问题