1. ホーム
  2. javascript

[解決済み] How to add a “readonly” attribute to an <input>?

2022-02-12 15:38:39

Question

How can I add readonly to a specific <input> ? .attr('readonly') does not work.

How to solved?

jQuery <1.9

$('#inputId').attr('readonly', true);

jQuery 1.9+

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

Read more about difference between prop and attr