使用jQuery将textarea变为只读 [英] Make textarea readonly with jquery

查看:61
本文介绍了使用jQuery将textarea变为只读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于文本input,我这样做:

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

但是我要为textarea做些什么,使其成为readonly.

But what should I do for textarea, to make it readonly.

推荐答案

将其包含在选择器中(使用多个/元素选择器),如下所示:

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

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

您可以在这里进行测试,如果这只是您的 事情在做,不需要 .each() ,您只需致电 .attr() .

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.

这篇关于使用jQuery将textarea变为只读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆