按钮点击Jade [英] Button clicks in Jade

查看:126
本文介绍了按钮点击Jade的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我点击按钮时执行javascript函数有困难,下面是我的玉文件

I'm having difficulty getting a button to execute a javascript function when it is clicked, below is my jade file

extends layout
block content
  - var something = function() {
  -   console.log('something')
  - }

  button(onclick='#{something()}') Click

我在哪里错了?

推荐答案

使用以下行:

button(onclick ='#{something() }')点击

你告诉Jade它应该将函数的内容粘贴到 onclick 属性。

you tell Jade that it should paste the content of the function into the value of the onclick attribute.

只需参考函数名称:

button(onclick='something()') Click

但这不起作用,因为该功能仅在Jade编译步骤中可用。
完成此步骤后,生成的HTML无法访问Jade中定义的变量。

But this won't work, because the function is only available in the Jade compile step. After this step the generated HTML has no access to the variables which was defined in Jade.

您需要包含JavaScript文件或使用脚本标记:

You need to include a JavaScript file or use the script tag:

script.
  var something = function() {
    console.log('something')
  }

button(onclick='something()') Click

这篇关于按钮点击Jade的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆