# 如何在Handlebars模板中禁用HTML按钮？

**URL:** https://meta.discourse.org/t/how-to-disable-a-html-button-in-a-handlebars-template/230664
**Category:** Development
**Created:** [2022年六月21日 20:07 UTC](https://meta.discourse.org/t/how-to-disable-a-html-button-in-a-handlebars-template/230664 "2022-06-21T20:07:16Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![p0fi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/p0fi/32/261315_2.png) [@p0fi](https://meta.discourse.org/u/p0fi)
#### Post date: [2022年六月21日 20:07 UTC](https://meta.discourse.org/t/how-to-disable-a-html-button-in-a-handlebars-template/230664/1 "2022-06-21T20:07:16Z")

</div>

我有一个使用 Handlebars 的主题组件。该组件是一个页脚，其中包含一个 HTML 表单按钮。我需要一旦点击就禁用该按钮。这通常很简单，看起来像这样

```html
<!DOCTYPE html>
<html>
    <body>
        <button onclick="this.disabled=true">Click here</button>
    </body>
</html>

```

但这在将其放入 Handlebars 模板后不起作用，因为它无法运行 JavaScript。所以我的问题是，如果按钮是在 Handlebars 模板中定义的，但这些模板无法运行任何 JavaScript，我该如何一旦点击就禁用我的页脚组件的按钮。
