是否可以禁用textarea的多行选项? [英] Is it possible to disable textarea's multiline option?
问题描述
当然,我可以使用标准html文本框,但由于某些原因我需要文本区域。
Of course, I can use standard html text box, but I need text area for some reason.
/ p>
So, is it possible to disable textarea's multiline option?
推荐答案
您可以使用 cols
和 rows
属性,并使其在CSS中不可调整大小,但不能阻止用户添加多行。即使该区域太小,滚动条也会出现,并让他们按自己的需要写入尽可能多的行。
You can set the size of your textarea using the cols
and rows
attributes and make it non-resizable in CSS but you can't prevent the user from adding more than one line. Even if the area is just too small, a scrollbar will appear and let them write as many lines as they want.
如果您确实需要只有一行,我建议将 rows
属性设置为1,并检查输入是否包含带有Javascript的单行。
If you really need to get just one line, I suggest setting the rows
attribute to 1 and checking if the input has a single line with Javascript.
<textarea name="a" cols="5" rows="1" ></textarea>
在CSS中:
textarea{
resize: none;
#You can use resize: horizontal if you just want to disable vertical resize
}
,则可以使用resize:horizontal
不过,我建议使用< input type =text... />
为什么要避免它?
这篇关于是否可以禁用textarea的多行选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!