简体   繁体   English

为什么复选框 onclick 功能不起作用?

[英]Why is checkbox onclick function not working?

Im building a flask app, but I cant figure out how to get the onclick event for the checkboxes to work.我正在构建一个烧瓶应用程序,但我无法弄清楚如何让复选框工作的 onclick 事件。 The function toggleAlarm should trigger a request but I'm not receiving anything.函数toggleAlarm应该触发一个请求,但我没有收到任何东西。 The click event for the button is working fine tough.按钮的点击事件工作正常。

''' '''

{% for alarm in alarms %} {{ alarm.time }} {{alarm.days}} {% for alarm in alarms %} {{ alarm.time }} {{alarm.days}}

  <button type="button" id="alarm-delete" class="close" onClick=deleteAlarm({{ alarm.id | safe }})>
    <span aria-hidden="true">&times;</span>
  </button>
  <label>
    {% if alarm.state == 1 %}
    <input type="checkbox" id="{{ alarm.id }}" onClick=toggleAlarm({{ alarm.id | safe }}) checked>  
    {% else %}
    <input type="checkbox" id="{{ alarm.id }}" onClick=toggleAlarm({{ alarm.id | safe }})> 
    {% endif %}
  </label>
</li>
{% endfor %}

''' '''

You're missing quotes for the onclick attribute.您缺少onclick属性的引号。

<input type="checkbox" id="{{ alarm.id }}" onClick=toggleAlarm({{ alarm.id | safe }})>

Should be应该

<input type="checkbox" id="{{ alarm.id }}" onclick="toggleAlarm({{ alarm.id | safe }});">

It's not required but you should also do onclick instead of onClick as that's the proper attribute camelCase name这不是必需的,但你也应该做onclick而不是onClick因为这是正确的属性 camelCase 名称

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

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