2010-09-24 63 views
1

我已经将下面这个伟大的脚本添加到我的代码的开头。使用Javascript的第一步:试图调试

<script type="text/javascript"> 

alert("pippo"); 


</script> 

它的工作原理:当我加载页面时,它显示一个小窗口与“pippo”。

如果我我报警后添加此如下:

$(document).ready(function() 
    // validate signup form on keyup and submit 


    $("#foo").validate({ 
     rules: { 
      'telephone[number]': { 
     number: true 
      } 
     }, 
     messages: { 
      'telephone[number]': "Please enter a telephone number" 

     } 
    }); 
}); 

,并重新加载它不会显示“皮波”任何more..Why的页面?

问候

哈维

+1

如果你是刚刚开始使用JavaScript缺少{的语法错误,请确保您得到自己极好的装备了。 :-) Chrome和Safari内置开发工具,只需从菜单中选择它们(或者至少在Chrome上按Ctrl + Shift + I)。 Firefox提供了出色的[Firebug](http://getfirebug.com/)插件。为了在IE中进行调试,你可以使用Visual Studio(这里有一个免费版本)。其中任何一个都会标记语法错误[ILMV指出](http://stackoverflow.com/questions/3785624/first-steps-with-javascript-trying-to-debug/3785642#3785642),并且他们提供的不仅仅是这些。 – 2010-09-24 09:16:42

回答

5
$(document).ready(function() { // <-- missing opening { 
    // validate signup form on keyup and submit 


    $("#foo").validate({ 
     rules: { 
      'telephone[number]': { 
     number: true 
      } 
     }, 
     messages: { 
      'telephone[number]': "Please enter a telephone number" 

     } 
    }); 
}); 

看第一行,works fine when fixed

0
$(document).ready(function() { 

失踪之初

+0

不,它在那里,它只是缩进错误,并且缺少'{'as [ILMV指出](http://stackoverflow.com/questions/3785624/first-steps-with-javascript-trying-to-debug/3785642 #3785642)。 – 2010-09-24 09:18:21

+0

请查看http://stackoverflow.com/posts/3785624/revisions – powtac 2010-09-24 13:12:05

1

这是因为你必须有一些无效的代码是不能被引擎解析,第一步:你有jQuery的加载?

0

您有一个语法错误,在{function()后面缺少{}。另外,确保你已经包含了jquery。

0

那是因为你的程序后 $(document).ready(function()