How to create string with multiple spaces in JavaScript

前端 未结 5 637
北海茫月
北海茫月 2020-12-08 06:37

By creating a variable

var a = \'something\' + \'        \' + \'something\'

I get this value: \'something something\'.

5条回答
  •  暖寄归人
    2020-12-08 07:33

    Use  

    It is the entity used to represent a non-breaking space. It is essentially a standard space, the primary difference being that a browser should not break (or wrap) a line of text at the point that this   occupies.

    var a = 'something' + '         ' + 'something'
    

    Non-breaking Space

    A common character entity used in HTML is the non-breaking space ( ).

    Remember that browsers will always truncate spaces in HTML pages. If you write 10 spaces in your text, the browser will remove 9 of them. To add real spaces to your text, you can use the   character entity.

    http://www.w3schools.com/html/html_entities.asp

    Demo

    var a = 'something' + '         ' + 'something';
    
    document.body.innerHTML = a;

提交回复
热议问题