如何在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 生日开业蛋糕祝福语简短