Jquery在PUG中不起作用。即使我已经包含了 jQuery 也无法识别 $ 符号



我已经将jquery代码放入pug模板中,但它没有运行。我正在尝试运行jQuery函数,但我得到了以下错误,尽管我也包含了jQuery文件:-

40|                 P   
41|                     script(type="text/javascript")
> 42|                        -  $("#image-drop-area").dropzone({ url: "/file/post" })

$ is not a function

这是我的pug模板:-

p
label(for="tags") Tags (Seperated by comma): 
input(type="text" name="tags" id="tags" required autofocus)
P   
script(type="text/javascript")
-  $("#image-drop-area").dropzone({ url: "/file/post" })

错误在于处理pug文件中的javascript/jquery行(使用-(。试试这个:

script(type="text/javascript").
$("#image-drop-area").dropzone({ url: "/file/post" })

注意末尾的点:script(type="text/javascript").。它将以下块作为纯文本写入script标记。

标记中的块

最新更新