【问题标题】:Jquery not working inside PUG. Isn't recognising $ sign even though I have included jQueryJquery 在 PUG 中不起作用。即使我包含了 jQuery,也无法识别 $ 符号
【发布时间】:2020-03-06 08:14:54
【问题描述】:

我已将我的 jquery 代码放在 pug 模板中,但它没有运行。我正在尝试运行 jQuery 函数,但即使我也包含了 jQuery 文件,我也会收到以下错误:-

 40|                 P   

    41|                     script(type="text/javascript")

  > 42|                        -  $("#image-drop-area").dropzone({ url: "/file/post" })


$ is not a function

这是我的哈巴狗模板:-

        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" })

【问题讨论】:

    标签: javascript jquery node.js pug


    【解决方案1】:

    错误是处理 pug 文件中的 javascript/jquery 行(带有-)。试试这个:

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

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

    Block in a Tag

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-26
      • 2023-03-09
      • 2020-10-01
      • 2019-07-27
      相关资源
      最近更新 更多