简体   繁体   English

如何从帕格文件中调用JavaScript函数?

[英]How can i call a javascript function from a file for pug?

Heres my code but removed some changed code to something smaller! 这是我的代码,但删除了一些更改后的代码!

Javascript code: JavaScript代码:

 // /JS function callme() { var test = 1 alert(test); } 

Pug code: 哈巴狗代码:

// /first.pug
var funct = require('../JS');
button(onclick='clickme()') click   
script.
function clickme() {¨
// trying to call callme function from my javascript file but i really dont know how.
    callme();
}

Sorry about this question i dont use pug but this was already made with pug so i cannot go changing it since it has alot more code but didnt post all not needed code here. 抱歉,这个问题我没有使用pug,但是已经用pug制作了,所以我无法更改它,因为它有很多代码,但是没有在这里发布所有不需要的代码。

Pug has no capability to directly run JavaScript. Pug无法直接运行JavaScript。 It is used to generate HTML. 它用于生成HTML。

You are already generating HTML with embedded client-side JavaScript. 您已经在使用嵌入式客户端JavaScript生成HTML。

You need to write the HTML to include the external JavaScript. 您需要编写HTML以包含外部JavaScript。

ie <script src="/url/to/JS.js"></script> <script src="/url/to/JS.js"></script>

In Pug that would be: 在帕格中将是:

script(src="/url/to/JS.js")

Make sure your HTTP server gives the JS a public URL! 确保您的HTTP服务器为JS提供了公共URL!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM