如何在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
热门推荐
6 薛之谦祝福语简短
10 横幅元旦祝福语大全简短
11 生日祝福语短句简短霸气
12 新年祝福语大全简短老师
13 给司机老师祝福语简短
14 简短佛教新年祝福语大全
15 猪年幽默祝福语简短
16 中秋祝福语简短版大全
17 朋友祝福语两字简短
18 圣诞简短祝福语给父母