如何在JavaScript中的第一个字符串中添加两个带有空格的字符串?
要添加两个字符串,我们需要一个'+'运算符来在字符串之间创建一些空间,但是当第一个字符串本身包含空格时,就无需显式分配空间。
在下面的示例中,由于字符串'str1'中包含空格,因此仅串联 而没有空格就足以添加两个字符串。
示例
<html>
<body>
<script>
function str(str1, str2) {
return (str1 + str2);
}
document.write(str("tutorix is the best ","e-learning platform"));
</script>
</body>
</html>输出结果
tutorix is the best e-learning platform
如果第一个字符串中没有空格,则必须创建space(“”)并将两个字符串连接起来,如下所示。
示例
<html>
<body>
<script>
function str(str1, str2) {
return (str1 + " " + str2);
}
document.write(str("tutorix is the best","e-learning platform"));
</script>
</body>
</html>输出结果
tutorix is the best e-learning platform
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短