string.repeat tab/whitespace 无法在 span 中工作
string.repeat tab/whitespace not working in span
我现在正在尝试为 'child' table 行添加空格 string.repeat,但是,在我的 span
元素中,它不起作用在 textareas
.
工作
这是我的 HTML:
<span id="first"></span>
<span id="second"></span>
<span id="third"></span>
这是我的 JS:
$('#first').append('Help');
$('#second').append(' '.repeat(4) + 'Help');
$('#third').append(' '.repeat(4) + 'Help');
Link 与 spans
:
的 jsfiddle
http://jsfiddle.net/JoshB1997/mbzjedxr/
Link 到相同的代码,但 textareas
除了 spans
:
http://jsfiddle.net/JoshB1997/mbzjedxr/1/
为什么它在 span 上不起作用,有什么方法可以让它起作用吗?
HTML 中的多个 space 显示为单个 space。参见 Why do multiple spaces in an HTML file show up as single spaces in the browser?。
要在 DOM 中添加多个 space,请使用
实体。
$('#second').append(' '.repeat(4) + 'Help');
我现在正在尝试为 'child' table 行添加空格 string.repeat,但是,在我的 span
元素中,它不起作用在 textareas
.
这是我的 HTML:
<span id="first"></span>
<span id="second"></span>
<span id="third"></span>
这是我的 JS:
$('#first').append('Help');
$('#second').append(' '.repeat(4) + 'Help');
$('#third').append(' '.repeat(4) + 'Help');
Link 与 spans
:
http://jsfiddle.net/JoshB1997/mbzjedxr/
Link 到相同的代码,但 textareas
除了 spans
:
http://jsfiddle.net/JoshB1997/mbzjedxr/1/
为什么它在 span 上不起作用,有什么方法可以让它起作用吗?
HTML 中的多个 space 显示为单个 space。参见 Why do multiple spaces in an HTML file show up as single spaces in the browser?。
要在 DOM 中添加多个 space,请使用
实体。
$('#second').append(' '.repeat(4) + 'Help');