add eventhandler to jquery UI datepicker after its creation

北慕城南 提交于 2019-12-05 14:57:41

问题


I have the following scenario:

In my masterpage I have:

$(".datepicker").datepicker({
    changeYear: true,
    changeMonth: true,
    dateFormat: "dd/mm/yy",
    duration: 'fast'
});

With this, every input field that I assign the class "datepicker" to, shows the jquery UI datepicker when clicked.

Now I have a datepicker on a page that should have its "onSelect" event handled. What would be the way considered best practise to do this.

Options I see:

  • give that 1 datepicker another class, like datepickerWithSelectEvent. What I dont like about this solution is that I get duplicate code for initializing the changeYear, changeMonth, ... . If I want to change the datepickers in a project I'll have to remember changing this in 2 places
  • Somehow add the eventhandler after the creation of the datepicker. This seems cleanest, but I don't really know how to do it. Anyone?

回答1:


Have you tried:

$(".datepickerSelect").datepicker( 'option' , 'onSelect', function() {} );


来源:https://stackoverflow.com/questions/1204929/add-eventhandler-to-jquery-ui-datepicker-after-its-creation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!