avoid textarea rows/cols error?

て烟熏妆下的殇ゞ 提交于 2019-12-19 11:40:16

问题


I am using a few page validation tools one problem i have is they tell me textarea must have rows and cols attribute. If i am setting this in CSS or using display:none (and using it to hold raw text data) can i do something to skip? it seems like the only answer is rows="0" cols="0" each time i use it. But i have a feeling that is not a good solution.


回答1:


Stop using a textarea. If you want something to hold raw data, then use a <script> element (if you plan to access it with JS) or an input of type hidden (if you plan to submit it as form data).

Don't use semantics that say "Let the user enter data" if you don't plan to let the user enter data.




回答2:


I think, it's standard solution. It would be better to give larger values though, so that browsers with disabled CSS can show them correctly. For invisible data holders you can use <div> instead of <textarea>.




回答3:


David's answer is ultimately the right one. A quick note about required attributes, though: Many attributes are required to be present, but are not required to have a value - so <textarea rows="" cols=""></textarea> is perfectly valid.

Semantically, think of this as explicitly not specifying the rows or cols, which is different to <textarea></textarea> which is just ignoring the attributes completely.



来源:https://stackoverflow.com/questions/2649283/avoid-textarea-rows-cols-error

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