当我尝试在计算机上将其拉出页面时,我遇到了问题。我不明白这一点。就像当您单击互联网上的文件按钮并单击打开文件时,该文件显示为空白。有人可以帮助我理解它为什么这样做。感谢。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Week 10</title>
<script type="text/javascript">
/ *<![CDATA[ */
Var name;
firstName = "Valerie";
lastName ="Shipbaugh";
var placeOfBirth;
name=FirstName +"";
name += lastName;
placeOfBirth ="Houston";
placeOfBirth +=",Texas";
nameArray = name.split("");
/*]]>*/
</script>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
document.write("<p> My first name is : + nameArray[0]
+ "<br />");
document.write("My last name is: "+ nameArray[1]
+ "<br />");
*/
The brackets[] specifies alternate characters allowed in a patch pattern.
It uses metacharacters which are special characters that define the pattern matching rules ina regular experession.
*/
document.write("There are " + firstName.length
+ " characters in my first name" + " <br/>");
*/
This one called the length property.
This returns the number of characters in a string.
*/
document.write("I was born in " + placeOfBirth + " <br/>");
*/
With this string we are using concatenation operations.
*/
document.write("<p>My initials are: " + firstName.charAt(0) +
lastName.charAt(0) + "</p>");
*/
The last one return the character at the specific position in a text string
returns an empty string if the specified position is greater than the length of the string.
*/
//]]>
</script>
</body>
</html>
所以,我的评论是在哪里解释发生了什么是在错误的地方???
答案 0 :(得分:2)
当然它不起作用,评论块甚至都不对:
*/
The brackets[] specifies alternate characters allowed in a patch pattern.
It uses metacharacters which are special characters that define the pattern
matching rules ina regular experession.
*/
应该是:
/*
The brackets[] specifies alternate characters allowed in a patch pattern.
It uses metacharacters which are special characters that define the pattern
matching rules ina regular experession.
*/
另外,你真的应该避免使用document.write
。在某些情况下,这就是导致空白页面的原因(如果我没记错的话,在页面加载后使用它时)。
答案 1 :(得分:2)
查看浏览器报告的错误(例如,firefox中的工具 - >错误控制台)它会点亮错误,例如您不匹配的/**/
评论&amp;来自;
document.write("<p> My first name is : + nameArray[0]
此外,js区分大小写,因此其var
不是Var
,您应该使用它来定义所有变量,例如firstname
(您偶然将其称为Firstname
})等。
答案 2 :(得分:2)
有一种更通用的方法可以解决这个问题:
<html>
和</html>
到文件答案 3 :(得分:1)
JavaScript区分大小写 - 因此在脚本的第一部分中:
Var name; //var is with a lowecase "v"
firstName = "Valerie";
lastName ="Shipbaugh";
var placeOfBirth;
name=FirstName +""; //firstName was created with a lowecase "f"
后来你有了......
document.write("<p> My first name is : + nameArray[0]
+ "<br />");
你错过了那里的引用,应该是 document.write(“
我的名字是:”+ nameArray [0]
+“
”);
最后,评论打开和关闭如下:
/* comment */
不喜欢这个
*/ error */
修复这些内容会使脚本运行。然而,它没有做我怀疑你想要的。您正在尝试split()包含该名称的字符串,但没有什么可以拆分它。你需要在那之间添加一个空格并尝试这个:
nameArray = name.split(" ");
你可以在这里看到这个: http://jsfiddle.net/CM7fx/
答案 4 :(得分:0)
在多个浏览器中进行测试,并确保您启用了启用了javascript的ID'建议首先
答案 5 :(得分:0)
注释错误,变量名称区分大小写。这是一个没有注释的工作版本,你可以重新添加那些
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Week 10</title>
<script type="text/javascript">
var name;
var firstName = "Valerie";
var lastName ="Shipbaugh";
var placeOfBirth;
name= firstName + " " + lastName;
placeOfBirth ="Houston ,Texas";
var nameArray = name.split(" ");
</script>
</head>
<body>
<script type="text/javascript">
document.write("<p> My first name is : " + nameArray[0] + "<br />");
document.write("My last name is: " + nameArray[1] + "<br />");
document.write("There are " + firstName.length + " characters in my first name" + " <br/>");
document.write("I was born in " + placeOfBirth + " <br/>");
document.write("<p> My initials are: " + firstName.charAt(0) + lastName.charAt(0) + "</p>");
</script>
</body>
</html>