你能使用<textarea>吗?超出 <form> 的范围 [英] Can You Use <textarea> Outside the Scope of a <form>
问题描述
我想使用 标签在浏览器中提供的特性和功能.我只想用它来保存一大块信息,这些信息可以通过使用
<textarea>
标签附带的滚动条查看.
I want to use the features and functionality that the <textarea>
tag offers in browsers. I want to use it merely to hold a large block of information that can be viewed through the use of the scrollbars that come with the <textarea>
tag.
所以我的问题是我可以在不使用 <form></form>
标签的情况下使用它吗?
So my question is can I use it without using <form></form>
tags?
我想确保我在当代和未来的浏览器中正确使用它.
I want to be sure that I use it properly for contemporary and future browsers.
谢谢.
推荐答案
按照标准,textarea
元素应该是 form
元素的后代.HTML5 允许将 textarea
放在表单之外,但要填充 form
属性.
Following the standards the textarea
element should be a descendant of a form
element.
HTML5 allows to place textarea
outside the form but have a form
attribute filled.
参见:https://developer.mozilla.org/en-US/docs/HTML/HTML_Elements/textarea
但据我所知,在表单外使用 textarea
而没有 form
属性的主要浏览器中不会出现任何错误.
But as I know you'll not get any errors in major browsers using textarea
outside the form and without the form
attribute.
出于您在问题中描述的目的,您可以使用带有垂直滚动的 div
元素:http://jsfiddle.net/f0t0n/Ybznv/
For the purpose you've described in your question, you can just use a div
element with vertical scrolling: http://jsfiddle.net/f0t0n/Ybznv/
#log {
height: 256px;
width: 512px;
overflow: auto;
}
这篇关于你能使用<textarea>吗?超出 <form> 的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!