Format the text in JavaScript alert box

前端 未结 7 2308
广开言路
广开言路 2020-12-09 02:19

How can I format the text in a JavaScript alert box? I need a word in the text to be underlined.

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 02:27

    Underline a string using unicode character '\u0332', called a COMBINING LOW LINE

    function underline(s) {
        var arr = s.split('');
        s = arr.join('\u0332');
        if (s) s = s + '\u0332';
        return s;
    }
    
    var str = underline('hello world'); // "h̲e̲l̲l̲o̲ ̲w̲o̲r̲l̲d̲"
    
    alert(str);
    

    This method is not guaranteed to produce a smooth underline.

    Example of confirm() on Firefox 59:

提交回复
热议问题