dr897777 2015-09-09 05:26
浏览 35

选择时不添加datepicker类

I have been trying to add a class for selectable dates. And following is done to add a class

$('a.ui-state-default').addClass('myClass');
$('a.ui-state-highlight').removeClass('myClass');

$(".myClass").attr("style", "background:"+background_button+" !important; color:"+text_button+" !important;");

This is working fine.

But when I select a date in datepicker, it's again reverting back to normal style and the added class to ui-state-default is not coming.

  • 写回答

1条回答 默认 最新

  • dragon_9000 2015-09-09 05:49
    关注

    The problem is because the dom for the datepicker is redrawn many times, as you are applying the style only once after the redraw is will be lost.

    The solution is to use css classes and beforeShowDay callback to style the dates

    jQuery(function($) {
      var array = [];
      $('#dp').datepicker({
        dateFormat: 'dd M yy',
        beforeShowDay: function(dt) {
          return [1, 'my-style-class']
        }
      })
    });
    .my-style-class a.ui-state-default:not(.ui-state-highlight) {
      color: green;
    }
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.css">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script>
    
    <div id="dp"></div>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害