防止在datepicker上触发show事件 [英] prevent show event from firing when on datepicker
问题描述
我有一个引导日期选择器.我希望在首次单击输入框时触发show事件.但是,如果用户使用上一个和下一个箭头遍历月份,我不希望触发该事件.
I have a bootstrap datepicker. I want the show event to be fired when the input box is first clicked. However I don't want the event to be fired if the user is traversing through the months with the prev and next arrows.
这可能吗?
$('#sandbox-container input').datepicker({
autoclose: true
});
$('#sandbox-container input').on('show', function(e){
console.log('show event');
});
如果您运行小提琴,则当您第一次单击输入字段时,将看到消息记录(我想要这种行为).但是,如果您使用上一个和下一个箭头,您还将看到显示的消息.
If you run the fiddle you will see the message get logged when you first click the input field (I want that behavior). however you will also see that message displayed if you use the prev and next arrows.
JS Fiddler在这里- http://jsfiddle.net/LcqM7/611/
JS Fiddler is here - http://jsfiddle.net/LcqM7/611/
推荐答案
您将需要检查show
是否已在当前状态"下运行".
You will need to check if the show
already "run" in the current "state".
$('#sandbox-container input')
.on('show', function(e){
if (! $(this).data('showrun')) {
console.log('show event');
$(this).data('showrun', true);
}
})
.on('hide', function(e){
$(this).data('showrun', false);
})
.on('changeMonth', function(e){
console.log('change month event');
});
还有一个工作示例:
http://jsfiddle.net/k6b3yepb/
And a working example:
http://jsfiddle.net/k6b3yepb/
这篇关于防止在datepicker上触发show事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!