Bootstrap Datepicker更改点火3次 [英] Bootstrap Datepicker on change firing 3 times
问题描述
使用此日期选择器: https://github.com/eternicode/bootstrap-datepicker ,而不是较旧的eyecon.ro一个。
$(。date-picker)。on(change,function(e){
contents = $(this).val();
id = $(this) ('id');
console.log(onchange contents:+ contents);
console.log(onchange id:+ id);
}) ;
HTML:
code>< input id =start_datetype =textdata-date-format =yyyy-mm-ddclass =date-picker form-control/>
除了更改之外,我还使用了其他一些选项,如
$('。date-picker')。datepicker()。change(function(){};
pre>
但是这并不关闭日期选择器,希望有一个简单的解决方案。thx
解决方案它没有解决问题,但是我正在使用datepicker通过ajax发送,所以3个更改事件导致我的问题 - 第三个事件总是失败,即使文档说要使用changeDate事件,对我来说,触发输入标签的更改事件似乎不是正确的3次,值不会更改3次!
我写了一个简单的去抖动功能来解决问题,不能解决这个问题 - 这是由于方法被触发的多个更改事件:setValue(第508行)_setDate :(行1048)和setValue(第508行)版本1.3.0)。
var last JQueryTS = 0; //这是一个全局变量。
....
//在更改事件处理程序...
var send = true;
if(typeof(event)=='object'){
if(event.timeStamp - lastJQueryTS< 300){
send = false;
}
lastJQueryTS = event.timeStamp;
}
if(send){
post_values(this);
}
它很简单,只需找到jquery'event',并确保在300ms的窗口中的值将被忽略。在我的测试中,这一切发生在30毫秒左右。
Hi I have been trying to just get the date of a bootstrap date picker and have been able to but it seems to fires 3 times. NOTE: This is not jquery date picker but bootstrap date picker.
Using this date picker: https://github.com/eternicode/bootstrap-datepicker, not older eyecon.ro one.
$(".date-picker").on("change", function(e) { contents = $(this).val(); id = $(this).attr('id'); console.log("onchange contents: " + contents); console.log("onchange id: " + id); });
HTML:
<input id="start_date" type="text" data-date-format="yyyy-mm-dd" class="date-picker form-control" />
I have used a few other options other than change, like
$('.date-picker').datepicker().change(function(){};
But this does not close date picker, hoping there is an easy solution to this. thx
解决方案it does not fix the problem, but i was using the datepicker to send through an ajax post, so the 3 change events was causing me problems - the 3rd event always failed. even if the documentation says to use a changeDate event, it doesn't seem right to me to fire the input tag's change event 3 times. the value isn't changing 3 times!
I wrote a simple 'debounce' function to get around the problem. doesn't fix the issue - which is due to multiple change events being fired from the methods: setValue (line 508) _setDate:(line 1048) and setValue (line 508) (version 1.3.0) of the widget.
var lastJQueryTS = 0 ;// this is a global variable. .... // in the change event handler... var send = true; if (typeof(event) == 'object'){ if (event.timeStamp - lastJQueryTS < 300){ send = false; } lastJQueryTS = event.timeStamp; } if (send){ post_values(this); }
it is pretty simple, just finds the jquery 'event', and makes sure that values in a window of 300ms are ignored. in my testing this all happened in 30 msec or so.
这篇关于Bootstrap Datepicker更改点火3次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!