【发布时间】:2017-10-16 00:52:28
【问题描述】:
我想在 highcharts 的工具提示中换行。我为此添加了 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
},
我浏览了以下链接并尝试了建议的解决方案,但似乎没有任何效果。 How can I add line break to html text without using any html tag
Give a line break without using <br/>
还有其他方法可以在字符串中添加换行符吗?请帮忙。
【问题讨论】:
-
<br>标签上没有右斜杠。 developers.whatwg.org/text-level-semantics.html#the-br-element -
@Rob Please see this question.
-
@SpencerWieczorek 请参阅此 HTML 标准:developers.whatwg.org/text-level-semantics.html#the-br-element
-
引起问题的不是 br 标签。它使用了在 IE11 和边缘浏览器中无法识别的 符号。即使使用
标签,换行符也能正常工作。 -
我并不是说您使用
<br>会导致问题。我的评论是对您对标签的使用情况的评论。
标签: javascript html angularjs highcharts