如何在 HTML 的标题属性中添加新的换行符/换行符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18606877/
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
How can I add new line/linebreak character in title attribute in HTML
提问by user26
I am using this
我正在使用这个
<a href="#" title="select from 1: this 2: that" > Click here </a>
<a href="#" title="select from 1: this 2: that" > Click here </a>
When someone hover over it I see all the text in one line.
当有人将鼠标悬停在它上面时,我会在一行中看到所有文本。
Is there any way to show it on new line?
有没有办法在新行上显示它?
回答by skulled
You can use 
or
.
您可以使用
或
。
<a href="#" title="select from 1: this 
 2: that" > Click here </a>
<a href="#" title="select from 1: this 
 2: that" > Click here </a>
回答by AlastairC
As you tagged this with accessibility, I would say the most robust approach is not to rely on the title for information.
当你用可访问性标记它时,我想说最可靠的方法是不要依赖标题来获取信息。
The current HTML specdiscourages this use as people using who cannot use a mouse (e.g. due to mobility impairment) but use a keyboard and see the screen will never see your tooltip/title text. People using touch screens cannot access it.
在当前的HTML规范不鼓励这种用作使用谁不能使用鼠标的人(例如,由于行动不便),但使用键盘和看到的画面将永远不会看到你的提示/标题文本。使用触摸屏的人无法访问它。
Most people using a screen reader will not be aware of the title text either, although it is possible to access in most screen readers it is not read out by default, and someone would have to know to look for it. (And there are more issues.)
大多数使用屏幕阅读器的人也不会知道标题文本,尽管可以在大多数屏幕阅读器中访问它,但默认情况下它不会被读出,并且必须有人知道才能找到它。(还有更多问题。)
The spec suggests using this for line breaks:
规范建议将其用于换行:
If the title attribute's value contains "LF" (U+000A) characters, the content is split into multiple lines. Each "LF" (U+000A) character represents a line break.
如果标题属性的值包含“LF”(U+000A) 字符,则内容将拆分为多行。每个“LF”(U+000A)字符代表一个换行符。
However, the display of the new lines is dependant on the browser (How can I use a carriage return in a HTML tooltip).
但是,新行的显示取决于浏览器(如何在 HTML 工具提示中使用回车)。
I suspect that the overall UI approach needs a little more thought, as many people would be confused by the sort of instruction in your example, i.e. what does clicking on it achieve if there are multiple options?
我怀疑整个 UI 方法需要多考虑一下,因为很多人会被您示例中的那种指令弄糊涂,即如果有多个选项,单击它会实现什么?
If your situation makes it difficult to write good link textthen I would post up more about the interaction at the UX stackexchange.
如果您的情况使编写好的链接文本变得困难,那么我会在UX stackexchange 上发布更多有关交互的信息。
回答by Gaurav
if you are generating it dynamically put \n
如果你是动态生成它把 \n
$(td).attr("title", "One \n Two \n Three");
回答by vishalkin
<a href="#" title="select from
1: this
2: that" > Click here </a>