Can You Use <textarea> Outside the Scope of a <form>

你说的曾经没有我的故事 提交于 2019-11-30 04:13:23

问题


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.

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.

Thanks.


回答1:


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.

See: https://developer.mozilla.org/en-US/docs/HTML/HTML_Elements/textarea

But as I know you'll not get any errors in major browsers using textarea outside the form and without the form attribute.

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;
}



回答2:


yes you can, but if its just scrolling use a div instead and style it like this in css:

example:

div {
overflow-x:scroll;
height:200px;
width:200px;
border:solid black 1px;
}

demo: http://jsbin.com/ugusos/2/edit




回答3:


Yes you can use textarea tags outside of a form and they will display and allow text to be inserted and edited, but not being tied to a form their uses will likely be limited. Although I suppose you could always use document.getElementById("") for the text area...




回答4:


Yes, you can use outside of a form,

But you could also use a div element and then use the contenteditable Attribute so that a user can edit the information.

http://html5doctor.com/the-contenteditable-attribute/




回答5:


Yes, you can use textarea outside of form; there is no problem in it.
PS: But there is no good reason to use textarea out or form. You can use div instead.



来源:https://stackoverflow.com/questions/14528951/can-you-use-textarea-outside-the-scope-of-a-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!