Make textarea readonly with jquery

前端 未结 6 1732
醉梦人生
醉梦人生 2020-12-14 00:28

For text input I do:

$(\'input[type=\"text\"]\').each(function(){
  $(this).attr(\'readonly\',\'readonly\');
});

But what shou

6条回答
  •  我在风中等你
    2020-12-14 01:05

    Include it in your selector (using a multiple/element selector), like this:

    $('input[type="text"], textarea').attr('readonly','readonly');
    

    You can test it here, if it's the only thing you're doing, there's no need for a .each(), you can just call .attr() on all matched elements.

提交回复
热议问题