使用jQuery将textarea变为只读 [英] Make textarea readonly with jquery
本文介绍了使用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屋!
查看全文