如何在JavaScript中的数组值中使用换行符?
要在每次出现〜时在数组值中添加换行符,请首先拆分数组。拆分后,为〜的每次出现添加换行符,即<br>。
例如,
This is demo text 1!~This is demo text 2!~~This is demo text 3!
这将为〜出现添加如下换行符:
This is demo text 1! This is demo text 2! This is demo text 3!
示例
<!DOCTYPE html>
<html>
<body>
<h2>Adding line break</h2>
<script>
var myArray = 'This is demo text 1!~This is demo text 2!~~This is demo text 3!~This is demo text 4!~~This is demo text 5!';
document.write("Original Array: "+myArray);
var brk = myArray.split('~');
var res = brk.join(" <br> ");
document.write("<br><br>"+res);
</script>
<p>Each occurence of ~ adds a line break above.</p>
</body>
</html>热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短