How can I use jQuery to make an input readonly?

后端 未结 13 2163
挽巷
挽巷 2020-12-07 09:54

I have the following input:

  

How c

13条回答
  •  时光取名叫无心
    2020-12-07 10:27

    You can do this by simply marking it disabled or enabled. You can use this code to do this:

    //for disable
    $('#fieldName').prop('disabled', true);
    
    //for enable 
    $('#fieldName').prop('disabled', false);
    

    or

    $('#fieldName').prop('readonly', true);

    $('#fieldName').prop('readonly', false);

    --- Its better to use prop instead of attr.

提交回复
热议问题