JQuery clockpicker 未触发输入更改事件
JQuery clockpicker not triggering change event on input
在我正在处理的代码库中,有这种类型的回调绑定,只要任何输入发生变化,就必须发生某些事情
$(document.body).on('change', '.input-sm', function (){
...
})
事实是,一些输入短信是通过时钟选择器更改的,这不会触发 'change' 事件。我将如何进行这项工作?理想情况下,我希望 clockpicker 触发更改事件。
http://jsfiddle.net/4zg3w5sj/7/
编辑:回调被同时绑定到带有时钟选择器的多个输入,所以我不能使用输入变量来触发更改事件(除非我明确地迭代我猜的输入)
您可以使用时钟选择器回调
beforeHourSelect : callback function triggered before user makes an
hour selection
afterHourSelect : callback function triggered after user makes an
hour selection
beforeDone : callback function triggered before time is written to
input
afterDone : callback function triggered after time is written to input
input.clockpicker({
autoclose: true,
afterDone: function() {
input.trigger("change");
}
});
我已经弄清楚问题了
插件触发更改事件但他们使用 triggerHandler instead of trigger 这意味着你不能在 body 上添加侦听器,你必须直接在输入上侦听
// Hours and minutes are selected
ClockPicker.prototype.done = function() {
raiseCallback(this.options.beforeDone);
this.hide();
var last = this.input.prop('value'),
value = leadingZero(this.hours) + ':' + leadingZero(this.minutes);
if (this.options.twelvehour) {
value = value + this.amOrPm;
}
this.input.prop('value', value);
if (value !== last) {
this.input.triggerHandler('change');
if (! this.isInput) {
this.element.trigger('change');
}
}
if (this.options.autoclose) {
this.input.trigger('blur');
}
raiseCallback(this.options.afterDone);
};
在此处查看修复程序
var input = $('#input-a');
var value = input.val();
// bind multiple inputs
$('.myinput').clockpicker({
autoclose: true,
afterDone: function() {
console.log("test");
}
});
// in the actual code it's not tied to an id but to a non-unique class
// does not trigger if changed by clock-picker
$(".myinput").on('change', function(){
console.log("!!!!")
})
在我正在处理的代码库中,有这种类型的回调绑定,只要任何输入发生变化,就必须发生某些事情
$(document.body).on('change', '.input-sm', function (){
...
})
事实是,一些输入短信是通过时钟选择器更改的,这不会触发 'change' 事件。我将如何进行这项工作?理想情况下,我希望 clockpicker 触发更改事件。
http://jsfiddle.net/4zg3w5sj/7/
编辑:回调被同时绑定到带有时钟选择器的多个输入,所以我不能使用输入变量来触发更改事件(除非我明确地迭代我猜的输入)
您可以使用时钟选择器回调
beforeHourSelect : callback function triggered before user makes an hour selection
afterHourSelect : callback function triggered after user makes an hour selection
beforeDone : callback function triggered before time is written to input
afterDone : callback function triggered after time is written to input
input.clockpicker({
autoclose: true,
afterDone: function() {
input.trigger("change");
}
});
我已经弄清楚问题了
插件触发更改事件但他们使用 triggerHandler instead of trigger 这意味着你不能在 body 上添加侦听器,你必须直接在输入上侦听
// Hours and minutes are selected
ClockPicker.prototype.done = function() {
raiseCallback(this.options.beforeDone);
this.hide();
var last = this.input.prop('value'),
value = leadingZero(this.hours) + ':' + leadingZero(this.minutes);
if (this.options.twelvehour) {
value = value + this.amOrPm;
}
this.input.prop('value', value);
if (value !== last) {
this.input.triggerHandler('change');
if (! this.isInput) {
this.element.trigger('change');
}
}
if (this.options.autoclose) {
this.input.trigger('blur');
}
raiseCallback(this.options.afterDone);
};
在此处查看修复程序
var input = $('#input-a');
var value = input.val();
// bind multiple inputs
$('.myinput').clockpicker({
autoclose: true,
afterDone: function() {
console.log("test");
}
});
// in the actual code it's not tied to an id but to a non-unique class
// does not trigger if changed by clock-picker
$(".myinput").on('change', function(){
console.log("!!!!")
})