我写了一些工作正常的代码,但我想在字符串之间创建一个空格。
我的代码是:
<html>
<head>
<title> Concatenating Strings </title>
</head>
<body>
<script type = "text/javascript">
var greetingString = "Hello";
var myName = prompt ("Please enter your name","");
var concatString;
document.write(greetingString + "" + myName + "<br>");
concatString = greetingString + "" + myName;
document.write(concatString);
</script>
</body>
</html>
目前脚本显示HelloMichael,我希望它能显示Hello Michael。有人可以告诉我如何做到这一点吗?
答案 0 :(得分:1)
在hello和michael之间加一个空格,如下所示:
concatString = greetingString + " " + myName; //notice the space in the string
答案 1 :(得分:1)
要插入空格字符,只需插入空格字符即可。例如:
greetingString + " " + myName
您当前的输出中没有空格,因为""
中没有空格。
答案 2 :(得分:0)
concatString = greetingString + " " + myName;
只需更改您的&#34;&#34;到&#34; &#34;,第二个有空格。