[英]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">×</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.