Urb*_*bKr 1 javascript jquery jquery-plugins
在我正在处理的代码库中,有这种类型的回调绑定,每当任何输入发生更改时都会发生某些事情
$(document.body).on('change', '.input-sm', function (){
...
})
Run Code Online (Sandbox Code Playgroud)
问题是,一些输入短信是通过时钟选择器更改的,它不会触发“更改”事件。我将如何使这项工作?理想情况下,我希望时钟选择器触发更改事件。
http://jsfiddle.net/4zg3w5sj/7/
编辑:回调同时被绑定到带有时钟选择器的多个输入,所以我不能使用输入变量来触发更改事件(除非我明确地迭代我猜的输入)
您可以使用时钟选择器回调
beforeHourSelect : 用户选择小时前触发的回调函数
afterHourSelect : 用户选择小时后触发的回调函数
beforeDone : 在时间写入输入之前触发的回调函数
afterDone : 时间写入输入后触发的回调函数
input.clockpicker({
autoclose: true,
afterDone: function() {
input.trigger("change");
}
});
Run Code Online (Sandbox Code Playgroud)
我已经弄清楚问题了
该插件触发更改事件,但它们使用triggerHandler而不是触发器,这意味着您不能在 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);
};
Run Code Online (Sandbox Code Playgroud)
在这里看到一个修复
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("!!!!")
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4165 次 |
| 最近记录: |