【发布时间】:2019-01-03 09:35:21
【问题描述】:
我有表单,提交按钮上的点击事件侦听器在哪里。单击提交按钮时,按钮上的事件单击事件侦听器会被触发,但不会提交表单。
这是我的代码:
<!-- HTML -->
<form action="/customer/create" method="post">
<input type="text" name="email">
<button type="submit" class="has-button-spinner">Create Customer</button>
</form>
<!-- JS -->
const buttons = document.querySelectorAll('.has-button-spinner');
buttons.forEach((button) => {
button.addEventListener('click', (e) => {
const target = e.currentTarget;
target.classList.add('is-loading');
target.setAttribute('disabled', true);
});
});
【问题讨论】:
标签: javascript html forms ecmascript-6 ecmascript-5