[英]How to force a line break without using <br/>
我想在图表的提示中打断一行。 我添加了br标签来这样做,并且效果很好。 唯一的问题是我也在尝试对该特定字符串执行本地化。
gettextCatalog.getString("Click the bar to view <br/>detailed information about <br/>events for the time range <br/>represented by the bar.");
使用br标签可防止IE11和边缘浏览器由于<>符号而本地化该字符串。 所以我需要找到一种无需使用即可打破界限的方法
标签。 我尝试了LTE和GTE替换<>标签。 它在所有浏览器中启用本地化,但不执行换行符。
我什至尝试:
gettextCatalog.getString("Click the bar to view \n detailed information about <br/>events for the time range");
higcharts-tooltip代码:
tooltip: {
formatter: function () {
var content;
var nameLabel;
content = "<strong>" + gettextCatalog.getString("Event Time") + ":</strong> " + Highcharts.dateFormat("%H:%M:%S", this.x) + "<br/>";
nameLabel = this.series.name;
if (nameLabel === highCardinalitySelector) {
nameLabel = otherLabel;
}
content += "<strong>" + $scope.eventfieldName + ":</strong> " + nameLabel + "<br/><strong>" + eventCountTypeLabel + ":</strong> " + this.y.toFixed(decimals) + "<br/>"; // jscs:ignore maximumLineLength
if ($scope.chartType == "Stacked Bar 2D") {
content += "<strong>" + gettextCatalog.getString("Total") + ":</strong> " + this.point.stackTotal.toFixed(decimals) + "<br/>";
}
content += "<br/>";
content += gettextCatalog.getString("Click the bar to view" + String.fromCharCode(13) + String.fromCharCode(10) + "\n detailed information about \nevents for the time range \n represented by the bar."); // jscs:ignore maximumLineLength
return content;
},
style: {
color: "#333",
fontSize: "11px",
padding: "8px"
},
borderColor: "#CCC",
followPointer: true
},
我浏览了以下链接并尝试了建议的解决方案,但似乎没有任何效果。 如何在不使用任何html标记的情况下向html文本添加换行符
还有其他方法可以在字符串中添加换行符吗? 请帮忙。
Javascript String.fromCharCode()函数从Unicode字符代码生成一个字符串。 在您的情况下,相关的字符代码可能是10行换行。
所以你的陈述会变成
gettextCatalog.getString(
"Click the bar to view" + String.fromCharCode(10) +
"detailed information about" + String.fromCharCode(10) +
"events for the time range" + String.fromCharCode(10) +
"represented by the bar.");
如果这样不起作用,您可以尝试String.fromCharCode(13)。
如果仍然无法解决问题,您可能会绝望地尝试使用13,然后再尝试10。
gettextCatalog.getString(
"Click the bar to view"
+ String.fromCharCode(13)
+ String.fromCharCode(10)
+ "detailed information about"
+ String.fromCharCode(13)
+ String.fromCharCode(10)
+ "events for the time range"
+ String.fromCharCode(13)
+ String.fromCharCode(10)
+ "represented by the bar.");
哪一种效果最好取决于工具提示显示处理程序的期望。 10很有可能会自己工作。
(请让我们知道它是否有效,以及是否有效。)
您可以将样式设置为white-space: pre-line
在包含字符串的元素上添加换行符,然后仅使用常规换行符(Javascript中为\\n
)。 我不知道这是否适用于您正在使用的翻译库。
最好在工具提示元素上设置最大宽度,并且根本不使用硬编码的换行符。
我意识到我以前的回答可能会误解您的问题,而您的问题实际上可能是在选择将换行符放在第一位的情况。
记住,用另一种语言
(a)句子片段的长度可能与英语的长度不同,并且
(b)我们使用英语的地方可能不会留下目的地语言的可翻译片段。
因此,也许您应该编写一个简单的函数以在翻译后添加换行符,或者,如果这是工具提示软件的固有功能,甚至可以设置工具提示以插入自己的换行符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.