jquery datepicker onselect事件处理程序多次 [英] jquery datepicker onselect event handler multiple times
问题描述
我正在尝试在jquery datePicker对象上处理相同的onSelect事件两次。从我理解的事件可以多次处理,但是当我尝试这个只有一个事件处理程序被解雇。似乎是第二个处理程序,但不是第一个。我如何处理相同的onSelect事件两次而不覆盖第一个?这是问题代码片段。
I am trying to handle the same onSelect event on a jquery datePicker object twice. From what i understand the event can be handled multiple times, but when i try this only one of the event handlers gets fired. It seems to fire the second handler, but not the first. How can i handle the same onSelect event twice without overriding the first one? This is the problem code snippet.
$(document).ready(function(){
$('.test').datepicker();
...
$('.test').datepicker('option', 'onSelect', function(dateText, inst) { alert('one'); });
}
...
$(document).ready(function(){
$('.test').datepicker('option', 'onSelect', function(dateText, inst) { alert('two'); });
}
推荐答案
您正在使用的代码只是替换第一个onSelect处理程序,如果你想做两件事情,需要先获取现有的onSelect处理程序,然后从您正在替换的处理程序中调用它。
The code you're using is just replacing the first onSelect handler with the second. If you want to do two things, then you'll need to first get the existing onSelect handler then call it from within the handler that you are replacing it with.
$(function() {
$('.test').datepicker();
$('.test').datepicker('option', 'onSelect', function(dateText,inst) { alert('one'); } );
var prevHandler = $('.test').datepicker('option','onSelect');
$('.test').datepicker('option', 'onSelect', function(dateText,inst) { prevHandler(dateText,inst); alert('two'); } );
});
这篇关于jquery datepicker onselect事件处理程序多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!