Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 有人能告诉我他们看到了吗_Javascript - Fatal编程技术网

Javascript 有人能告诉我他们看到了吗

Javascript 有人能告诉我他们看到了吗,javascript,Javascript,当我试图在我的电脑上调出它时,我遇到了问题,页面是空白的。我不明白这一点。就像当你点击互联网上的“文件”按钮,然后点击“打开文件”时,文件显示为空白。有人能帮我理解它为什么这么做吗。谢谢 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www

当我试图在我的电脑上调出它时,我遇到了问题,页面是空白的。我不明白这一点。就像当你点击互联网上的“文件”按钮,然后点击“打开文件”时,文件显示为空白。有人能帮我理解它为什么这么做吗。谢谢

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

第10周
/ **/
//");
document.write(“我的姓是:”+nameArray[1]
+“
”; */ 方括号[]指定修补程序模式中允许的替换字符。 它使用元字符,元字符是在常规表达式中定义模式匹配规则的特殊字符。 */ document.write(“有”+firstName.length +“我的名字中的字符”+“
”; */ 这个叫做length属性。 这将返回字符串中的字符数。 */ 写下“我出生在”+出生地+“
”; */ 对于这个字符串,我们使用连接操作。 */ 我的首字母是:“+firstName.charAt(0)+ lastName.charAt(0)+“

”; */ 最后一个返回文本字符串中特定位置的字符 如果指定的位置大于字符串的长度,则返回空字符串。 */ //]]>

因此,我的注释用于解释发生了什么是在错误的地方???

在多个浏览器中进行测试,并确保您首先启用了javascript id“建议”

当然它不会工作,注释块甚至不正确:

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

另外,你真的应该避免使用
文档。写
。在某些情况下,这就是导致空白页面的原因(如果我没记错的话,当你在页面加载后使用它时)。

查看浏览器报告的错误(例如firefox中的工具->错误控制台)它将显示错误,例如您的注释不匹配,
/***/
注释和中缺少的结束引号字符

document.write("<p> My first name is : + nameArray[0]
document.write(“我的名字是:+nameArray[0]

另外,js是区分大小写的,因此它的
var
不是
var
,您应该使用它来定义所有变量,例如
firstname
(您后来顺便称之为
firstname
)等。

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 />");
不是这样的

*/ error */
修复这些问题将使脚本运行。但是,它没有执行我怀疑您想要的操作。您正在尝试拆分()包含名称的字符串,但没有任何可拆分的内容。您需要在这两者之间添加一个空格,然后尝试以下操作:

nameArray = name.split(" ");
您可以在此处看到这一点:

有一种更通用的方法来解决此问题:

  • 从这个文件中取出所有内容,然后 把它复制到记事本上
  • 只放
    输入到文件中
  • 开始将非常小的块复制到 每次一个文件,每次一个 重新加载页面
  • 很快你就会明白 一个小的块导致 失败,然后你可以评估 小街区

  • 注释错误,变量名区分大小写。这是一个没有注释的工作版本,您可以重新添加这些注释

    
    第10周
    变量名;
    var firstName=“Valerie”;
    var lastName=“shippaugh”;
    出生地点;
    name=firstName+“”+lastName;
    placeOfBirth=“德克萨斯州休斯顿”;
    var nameArray=name.split(“”);
    document.write(“我的名字是:”+nameArray[0]+“
    ”); document.write(“我的姓是:“+nameArray[1]+”
    ”); document.write(“我的名字中有“+firstName.length+”个字符”+”
    ); 写下“我出生在”+出生地+“
    ”; 写(我的首字母是:“+firstName.charAt(0)+lastName.charAt(0)+”

    ”;
    您需要确保所有注释块都匹配,即/*和*/,引号也不匹配。更不用说
    Var
    必须始终是
    Var
    ,并且变量名也区分大小写。javascript中的代码格式错误,注释和语法错误太多。同样,作为好吧。你用来键入的编辑器肯定在某种程度上表明注释关闭了?语法高亮显示错误或类似的东西?@Andre-不,这都是IE的错。注释没有正确嵌套/编写。如果你只使用文本编辑器,试着使用记事本++或其他将显示语法高亮显示的编辑器,你使用的是什么编辑器g、 还有为什么你的脚本看起来是这样的..阅读一些好的编程实践..是的,我刚刚运行了这个,并且注释块是错误的。另外,当你尝试运行它时会出现错误。如果在IEI中我仍然在学习javascript,并且我们必须使用该文档,请确保脚本调试也已启用。write@ErikPerik-这就是我为什么说“页面加载后”。在过去,我不得不处理使用
    document.write
    导致我方严重并发症的情况(即joomla在帖子内容中注入javascript,因此我无法通过ajax简单嵌入帖子,因为正如我们所说,它清除了页面).Oh和split函数接受一个字符串,其中包含要查找的内容和拆分依据。如果有一个空字符串,则需要一个空格字符。+1用于将任务拆分为小块。也就是说,他有严重的编码问题,这给人的印象是,即使这些问题很小,他实际上也无法解决这些问题-一个明显的例子是c多明特街区。
    nameArray = name.split(" ");
    
         <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>