I have a listener of the focus event of an input but when entering that event, the modal is launched indefinitely.
$('.input').on('focus',function() {
$.confirm({
theme: 'material',
title: 'Atention',
content: '¿Content?',
useBootstrap: false,
boxWidth:'200px'
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.2.0/jquery-confirm.min.js"></script>
<input type="date" class="input">
But if I do something like the confirmation window is not displayed indefinitely
$(this).confirm({...});
What is the difference of using $.confirm
vs $(this).confirm
and why is the window shown so many times
To which the $ symbol refers is not to the input? Is not the same as (this) that refers to the input?
答案 0 :(得分:0)
如果您只需要发生一次事件,请考虑使用$('.input').one('focus',function(e) { ... }
。
jQuery Confirm库中的某些内容导致焦点在页面上的元素周围移动,多次触发您的事件。如果你触发alert
,也会发生同样的事情,因为焦点被采用然后返回到输入框。