包括哈巴狗模板中的jquery

问题描述 投票:0回答:1

我正在尝试包括jquery库以公开其某些功能。我遵循了教程,查看了示例,但收到一个奇怪的错误,清楚地表明我没有正确加载模块。

错误:

10|             script(src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous")
    11|             script
  > 12|                 $(document).ready(function(){
------------------------^
    13|                 $("button").click(function(){
    14|                     $("p").hide();
    15|                 });

unexpected text "$(doc"

现在,我以为我可以简单地使用经典脚本标签导入脚本,但是它不起作用。这是我的基本模板标题。

doctype html
html
    head  
        block head  
            meta(charset=utf-8)
            meta(viewport='viewport' content='width=device-width, initial-scale=1.0')
            link(rel='stylesheet', href='/css/style.css')
            link(rel='stylesheet', href='/css/testTables.css')
            link(rel='stylesheet', href='/css/tableStyles.css')
            script(src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous")
            script
                $(document).ready(function(){
                $("button").click(function(){
                    $("p").hide();
                });
                });

现在要澄清,它存储在项目根目录下的我的views文件夹中。我正在使用nodeJS并表达。我也有jquery包作为依赖项。我的项目也从此处定义的根目录/公共文件夹中提供。

//all the static assets are being served from public
app.use(express.static(path.join(__dirname,'public')));

[如果有人可以帮我,那真是太好了。谢谢!

jquery node.js express pug web-deployment
1个回答
0
投票

如果标签中包含文本块,则可以在脚本声明之后简单地添加.点。

script.
    $(document).ready(function(){
    $("button").click(function(){
        $("p").hide();
    });
    });

哈巴狗文档here很好解释。

© www.soinside.com 2019 - 2024. All rights reserved.