简体   繁体   English

使用换行符打破 HTML 工具提示消息

[英]Break HTML tooltip message using line breaks

I'm trying to break my custom HTML tooltip that I used inside the button Hover Button .我试图破坏我在按钮Hover Button中使用的自定义 HTML 工具提示。 I tried using different approach(ie., /n, &#013) in typescript as it's a custom tooltip to add a line break and nothing seem to work.我尝试在打字稿中使用不同的方法(即 /n、&#013),因为它是一个自定义工具提示来添加换行符,但似乎没有任何效果。

Below is the tooltip data that I'm using and the fiddle associated with the same:下面是我正在使用的工具提示数据以及与之相关的小提琴:

 tooltipData="Helo,Angular 2" + "&#013" + "This button is used to test hover message" + "/n" + "This message should come at the last"

Fiddle小提琴

Try this -试试这个 -

 <div title="Helo,Angular 2&#013;&#010;This button is used to test hover message&#009;This message should come at the last">Hover Me</div>

Here I used -在这里我用了 -

&#010; - for New line

I Hope this will work for you.我希望这对你有用。

You're using the wrong slash - new line should be \n not /n:您使用了错误的斜杠 - 新行应该是 \n 而不是 /n:

tooltipData="Helo,Angular 2" + "&#013" + "This button is used to test hover message" + "\n" + "This message should come at the last"

Update your fiddle to use \n rather than /n .更新您的小提琴以使用\n而不是/n

Hi this code will work in all browser !!i used for new line in chrome and safari and ul li for IE您好,此代码适用于所有浏览器!我在 chrome 和 safari 中用于换行,在 IE 中使用 ul li

function genarateMultiLIneCode(){
var =values["a","b","c"];
const liStart = '<li>';
      const liEnd = '</li>';
      const bullet = '&#8226; ';     
      var mergedString = ' ';
      const unOrderListStart='<ul>'
      const unOrderListEnd='</ul>'
      const fakeNewline = '&#013;&#010;';
      for (let i = 0; i < values.length; i++) {
           mergedString += liStart + bullet + values[i] + liEnd + fakeNewline;
      }
      const tempElement = document.createElement("div");
      tempElement.innerHTML = unOrderListStart + mergedString + unOrderListEnd;    
      return tempElement.innerText;
    }
}
    var =values["RAHUL","BIKASH","RAMAN"];
const liStart = '<li>';
      const liEnd = '</li>';
      const bullet = '&#8226; ';     
      var mergedString = ' ';
      const unOrderListStart='<ul>'
      const unOrderListEnd='</ul>'
      const fakeNewline = '&#013;&#010;';
      for (let i = 0; i < values.length; i++) {
           mergedString += liStart + bullet + values[i] + liEnd + fakeNewline;
      }
      const tempElement = document.createElement("div");
      tempElement.innerHTML = unOrderListStart + mergedString + unOrderListEnd;

then use tempElement.innerText然后使用tempElement.innerText

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM