How can I use jQuery to make an input readonly?

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

I have the following input:

  

How c

13条回答
  •  粉色の甜心
    2020-12-07 10:37

    In html

    $('#raisepay_id').attr("readonly", true) 
    
    $("#raisepay_id").prop("readonly",true);
    

    in bootstrap

    $('#raisepay_id').attr("disabled", true) 
    
    $("#raisepay_id").prop("disabled",true);
    

    JQuery is a changing library and sometimes they make regular improvements. .attr() is used to get attributes from the HTML tags, and while it is perfectly functional .prop() was added later to be more semantic and it works better with value-less attributes like 'checked' and 'selected'.

    It is advised that if you are using a later version of JQuery you should use .prop() whenever possible.

提交回复
热议问题