HTML:标签的换行符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1917934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:36:24  来源:igfitidea点击:

HTML: Newline character for label?

html

提问by Mike Pateras

I have a method that sets the text for a label, and I'd like to use it to display several lines of text. Is it possible to insert a character into the text for the label to do this?

我有一个设置标签文本的方法,我想用它来显示多行文本。是否可以在标签文本中插入一个字符来执行此操作?

回答by Joe Mabel

You have a few choices. If you can trust your callers, you can allow formatted text to be passed into the parameter (so someone can pass "<br />" as part of the label text. If you can slightlytrust them, you can still allow that one particular piece of HTML to come through while disallowing others, but you might want to put the intelligence in your function to limit how many breaks can come in one label.

你有几个选择。如果您可以信任您的调用者,您可以允许将格式化文本传递到参数中(因此有人可以将“<br />”作为标签文本的一部分传递。如果您可以稍微信任他们,您仍然可以允许特定的一段 HTML 可以通过而不允许其他人通过,但您可能希望将智能置于您的函数中以限制一个标签中可以出现的中断次数。

Another (more obscure) choice would be to designate some other character or sequence of characters that you know will never appear on a label to indicate a break (e.g. "#NEWLINE"), and have the function substitute "<br />" wherever that occurs.

另一个(更模糊)的选择是指定一些你知道永远不会出现在标签上的其他字符或字符序列来表示中断(例如“#NEWLINE”),并在任何地方使用函数替换“<br />”发生这种情况。

回答by 0xFF

Normally a simple <br/>tag will do it!!

通常一个简单的<br/>标签就可以做到!!