jquery-ui – 如何在按钮面板中将按钮添加到jQuery datepicker?

前端之家收集整理的这篇文章主要介绍了jquery-ui – 如何在按钮面板中将按钮添加到jQuery datepicker?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我只是将元素附加到面板包装器并调用.button()?

解决方法

如果要在滚动月份期间保持“清除”按钮,请使用onChangeMonthYear:。

一个例子:

  1. $( "#datepicker" ).datepicker({
  2. showButtonPanel: true,beforeShow: function( input ) {
  3. setTimeout(function() {
  4. var buttonPane = $( input )
  5. .datepicker( "widget" )
  6. .find( ".ui-datepicker-buttonpane" );
  7.  
  8. $( "<button>",{
  9. text: "Clear",click: function() {
  10. //Code to clear your date field (text Box,read only field etc.) I had to remove the line below and add custom code here
  11. $.datepicker._clearDate( input );
  12. }
  13. }).appendTo( buttonPane ).addClass("ui-datepicker-clear ui-state-default ui-priority-primary ui-corner-all");
  14. },1 );
  15. },onChangeMonthYear: function( year,month,instance ) {
  16. setTimeout(function() {
  17. var buttonPane = $( instance )
  18. .datepicker( "widget" )
  19. .find( ".ui-datepicker-buttonpane" );
  20.  
  21. $( "<button>",read only field etc.) I had to remove the line below and add custom code here
  22. $.datepicker._clearDate( instance.input );
  23. }
  24. }).appendTo( buttonPane ).addClass("ui-datepicker-clear ui-state-default ui-priority-primary ui-corner-all");
  25. },1 );
  26. }
  27. });

猜你在找的jQuery相关文章