Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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
Jade按钮和jQuery单击事件_Jquery_Pug - Fatal编程技术网

Jade按钮和jQuery单击事件

Jade按钮和jQuery单击事件,jquery,pug,Jquery,Pug,我不明白为什么它不起作用 我有这个index.jade文件: !!! 5 html head link(rel='stylesheet', href='/stylesheets/style.css') script(src="/javascripts/jquery-1.8.2.js") script $("#rollButton").click(function() { alert("sas"); });

我不明白为什么它不起作用

我有这个index.jade文件:

!!! 5
html
  head
    link(rel='stylesheet', href='/stylesheets/style.css')
    script(src="/javascripts/jquery-1.8.2.js")
           script
       $("#rollButton").click(function() {
          alert("sas");
       });
  body
     input#rollButton(type="button", value="Roll")
它应该会弹出警报!我错过了什么

生成的HTML似乎还可以:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/stylesheets/style.css">
<script src="/javascripts/jquery-1.8.2.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
$("#rollButton").click(function() {
  alert("sas");
});
</script>
</head>
<body>
<input id="rollButton" type="button" value="Roll">
</body>
</html>

$(“#滚动按钮”)。单击(函数(){
警报(“sas”);
});

我对[jade]还不熟悉,但是不应该有jQuery“onReady”函数,比如:

!!! 5
html
  head
    link(rel='stylesheet', href='/stylesheets/style.css')
    script(src="/javascripts/jquery-1.8.2.js")
    script
       $(document).ready(function(){
         $("#rollButton").click(function() {
          alert("sas");
         });
       });
  body
     input#rollButton(type="button", value="Roll")
编辑:我不确定缩进是什么。正如我在其他评论中看到的,它也应该被修复。

删除此项!!!五,

html
 head
link(rel='stylesheet', href='/stylesheets/style.css')
script(src="/javascripts/jquery-1.8.2.js")
       script
   $("#rollButton").click(function() {
      alert("sas");
   });
body
 input#rollButton(type="button", value="Roll")

只需查看生成的页面源代码?答案应该是显而易见的,你的脚本缩进是错误的,顺便说一句,如果你不想发疯的话,我会把html放在jade中,要求你的脚本在那里,然后把你的javascript代码写在另一个文件中。天哪,不敢相信我错过了$(文档)。准备好了,哈哈,已经挣扎了半个小时了。谢谢:)