一段时间后,广播组的火灾事件
我正在寻找一种解决方案,以便在一段时间后延迟后,让事件在广播组上开火。
具体来说,我需要询问用户一个问题,并想提交他们的输入而无需让用户单击单独的按钮。同时,在考虑答案时,用户可能会单击不同的无线电按钮。
OnInput
和OnChange
均在用户单击后立即发射。但是,还有另一个解决方案吗?
这是一个很小的例子:
<div class="form-check form-check-inline">
<label> What is 17 * 21? </label>
<br></br>
<input class="form-check-input" type="radio" id="MC_0" name="MC_first" value="1" oninput="console.log('here');">
<label for="MC_0" class="form-check-label">263</label>
<input class="form-check-input" type="radio" id="MC_1" name="MC_first" value="2" oninput="console.log('here');">
<label for="MC_1" class="form-check-label">357</label>
</div>
我很想拥有onutput
仅在此无线电组中没有活动的5秒之后起火。
I am searching for a solution to let an event fire on a radio group after some time delay.
Specifically, I need to ask users a question and want to submit their input without having the users click a separate button. At the same time, it shall be possible that the user clicks different radio buttons while considering the answer.
onInput
and onChange
are both fired immediately after a user click. However, is there another solution?
Here is small example:
<div class="form-check form-check-inline">
<label> What is 17 * 21? </label>
<br></br>
<input class="form-check-input" type="radio" id="MC_0" name="MC_first" value="1" oninput="console.log('here');">
<label for="MC_0" class="form-check-label">263</label>
<input class="form-check-input" type="radio" id="MC_1" name="MC_first" value="2" oninput="console.log('here');">
<label for="MC_1" class="form-check-label">357</label>
</div>
I would love to have oninput
only fire after, say, 5 seconds without activity in this radio group.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
OP需要选择一种结合和
debounced> debounced
处理回调-功能。要求是A(或每个在一个不仅仅是一个)射电组中需要完全嵌套在事件划分发生的父母结构中。并且每个原因的委派节点都需要在其相关
INPUT
-event上注册其自己的拒绝事件处理程序。另外,强烈建议对OP的标记进行重构。
The OP needs to choose an approach which combines event-delegation and the
debounced
handling of a callback-function.The requirements are that a (or each in case of more than just one) radio-group needs to be entirely nested within a parent-structure where the event-delegation takes place. And each delegation-node of cause needs to have its own debounced event-handler registered to its related
input
-event.Additionally a refactoring of the OP's markup is strongly recommended.
您可以使用
settimeout()
:You can use
setTimeout()
: