Add line break within tooltips

后端 未结 27 2501
北恋
北恋 2020-11-28 02:23

How can line breaks be added within a HTML tooltip?

I tried using
and \\n within the tooltip as follows:



        
27条回答
  •  醉梦人生
    2020-11-28 02:34

    The javascript version

    Since (html) is 0D (hex), this can be represented as '\u000d'

    str = str.replace(/\n/g, '\u000d');
    

    In addition,

    Sharing with you guys an AngularJS filter that replaces \n with that character thanks to the references in the other answers

    app.filter('titleLineBreaker', function () {
        return function (str) {
            if (!str) {
                return str;
            }
    
            return str.replace(/\n/g, '\u000d');
        };
    });
    

    usage

提交回复
热议问题