简体   繁体   English

有人可以告诉我他们是否看到了这个

[英]Can someone tell me if they see this

I am having problems when I try to pull it up on my computer the page is blank. 尝试将其拉到计算机上时出现问题,页面空白。 I am not understanding this. 我不明白这一点。 Like when you click on the file button on the internet and you click open file that file shows up blank. 就像当您单击Internet上的“文件”按钮并单击“打开文件”时,该文件显示为空白。 Can someone help me understand why it is doing that. 有人可以帮我理解为什么这样做吗。 Thanks. 谢谢。

    <!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>

So where my comments are to explain what is going on is in the wrong place??? 因此,在我的评论中要解释发生了什么的地方在错误的地方???

Of course it won't work, the comment blocks aren't even right: 当然,这是行不通的,注释块甚至不正确:

 */
 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.
 */ 

Should be: 应该:

 /*
 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.
 */ 

Also, you really should avoid using document.write . 另外,您实际上应该避免使用document.write In certain cases, that is what causes a blank page (if I remember correctly, when you use it after page load). 在某些情况下,这就是导致空白页的原因(如果我没记错的话,在页面加载后使用它时)。

Look at errors reported by the browser (tools->error console in firefox for example) it will hi-light errors such as you mismatched /**/ comments & the missing closing quote character from; 查看浏览器报告的错误(例如firefox中的tools-> error console),它将显示一些错误,例如/**/注释不匹配以及缺少的引号引起的错误;

document.write("<p> My first name is : + nameArray[0]

Also js is case sensitive so its var not Var , which you should use to define all your variables such as firstname (which you incidentally later refer to as Firstname ) etc. 同样的js是区分大小写,因此其varVar ,你应该使用它来定义你所有的变量,如firstname (你顺便后来所称的Firstname )等。

There is a more general way to solve this problem: 有一个更通用的方法可以解决此问题:

  1. Take everything out of this file and copy it into notepad. 从文件中取出所有内容并将其复制到记事本中。
  2. Put just the <html> and </html> into the file 仅将<html></html>放入文件中
  3. Begin copying very small blocks into the file one at a time, each time reload the page 开始一次将非常小的块一次复制到文件中,每次重新加载页面
  4. Soon you will see one small block that causes the failure, then you can assess that small block. 很快,您将看到一个导致故障的小块 ,然后您可以评估该小块。

JavaScript is case sensitive - so in the first section of your scripts: JavaScript区分大小写-因此,在脚本的第一部分中:

Var name;                      //var is with a lowecase "v"
firstName = "Valerie";
lastName ="Shipbaugh";
var placeOfBirth;
name=FirstName +"";            //firstName was created with a lowecase "f"

Later you have this... 以后你有这个...

document.write("<p> My first name is : + nameArray[0]
 + "<br />");

You're missing a quote in there, should be document.write(" 您在其中缺少引号,应该是document.write(“

My first name is : " + nameArray[0] + " 我的名字是:“ + nameArray [0] +”
"); “);

And finally, comments open and close like this: 最后,评论像这样打开和关闭:

/* comment */

Not like this 不是这样

*/ error */

Fixing these things will make the script run. 解决这些问题将使脚本运行。 However, it's not doing what I suspect you want. 但是,它并没有满足我的要求。 You are trying to split() the string containing the name, but there's nothing to split it on. 您正在尝试对包含名称的字符串进行split(),但没有任何拆分方法。 You need to add a space between then and try this: 您需要在此之间添加一个空格,然后尝试以下操作:

nameArray = name.split(" ");

You can see this working here: http://jsfiddle.net/CM7fx/ 您可以在这里看到此工作: http : //jsfiddle.net/CM7fx/

在多个浏览器中进行测试,并确保您已启用javascript身份ID'建议先

The comments were wrong, the variable name are case sensitive. 注释是错误的,变量名区分大小写。 Here is a working version without comments, you can re-add those 这是没有评论的有效版本,您可以重新添加

     <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM