Html 在标题属性中添加换行符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19981974/
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
Adding a line break in the title attribute
提问by Inventor
i would like to find out how to add a break in the title attribute, i would like to have breaks in the title attribute to differentiate the names. how can i add a break in the title attribute?
我想了解如何在 title 属性中添加中断,我想在 title 属性中添加中断以区分名称。如何在标题属性中添加中断?
i have something like this
我有这样的东西
<p title="this is a description of the some text <br> and further description">Some Text</p>
what comes out is:
出来的是:
回答by NoLifeKing
If you add a new line where you want line breaks, it works on SOME browsers, but not all.
如果您在需要换行的地方添加新行,它适用于某些浏览器,但不是所有浏览器。
Example:
例子:
div { background-color: #c3c3c3; display: block; width: 100px; height: 100px; }
<div title="This is a text
Second line
Third line!">Contents</div>
JSFiddle:
http://jsfiddle.net/g5CGh/
JSFiddle:http:
//jsfiddle.net/g5CGh/
回答by Ana
In the title text replace <br>
for <br />
在标题文本中替换<br>
为<br />
<p title="this is a description of the some text <br /> and further description">Some Text</p>
And now replace <br />
with a line break \n
(jquery):
现在用<br />
换行符\n
(jquery)替换:
<script>
$(document).ready(function(){
$('p').each(function(){
var a = $(this).attr('title');
var b = a.replace('<br />','\n');
$(this).attr('title', b);
});
});
</script>
Hope I've helped you
希望我帮助了你