简体   繁体   English

在jQuery UI Datepicker中向选定的日期添加特殊的类

[英]Add a special class to selected days in jQuery UI Datepicker

I'm trying to highlight a horizontal range of days in jQuery UI Datepicker with multiselect plugin. 我正在尝试使用multiselect插件突出显示jQuery UI Datepicker中的水平天数范围。 For highlighting I use the :before and :after pseudoelements of the a tags. 为了突出显示,我使用了a标签的:before:after伪元素。

.ui-state-highlight a:before,
.ui-state-highlight a:after {
    content: "";
    display: inline-block;
    position: absolute;
    width: 12px;
    height: 30px;
    background: #e84332;
    display: none;
}

.ui-state-highlight a:before {
    left: -7px;
}

.ui-state-highlight a:after {
    right: -8px;
}

Just need to show :before or :after element depending on position of the highlited day. 只需要显示:before:after元素就可以了。 But the datepicker removes the styling every time after rendering. 但是,日期选择器在渲染后每次都会删除样式。 Please, help me to understand, how to run the function that shows the pseudoelements AFTER the datepicker's rendering. 请帮助我理解,如何在datepicker渲染之后运行显示伪元素的函数。

Image of horizontal selection: 水平选择的图像:

http://i.stack.imgur.com/XBUUx.jpg http://i.stack.imgur.com/XBUUx.jpg

JSFiddle: JSFiddle:

https://jsfiddle.net/meecrobe/wrppLqy1/ https://jsfiddle.net/meecrobe/wrppLqy1/

Look at this answer: 看这个答案:

I wrote a small demo that does this... 我写了一个小演示来做到这一点...

I create an object literal that contains the extensions to $.datepicker and then do $.extend on $.datepicker and my object. 我创建了一个包含$ .datepicker扩展名的对象文字,然后对$ .datepicker和我的对象执行$ .extend。

You can check it out here: http://jsfiddle.net/NHN4g/4/ 您可以在这里查看: http : //jsfiddle.net/NHN4g/4/

Here's the extension itself: 这是扩展本身:

(function($){ var datepickerExtensions = { _oldAdjustDate: $.datepicker._adjustDate, _adjustDate: function(id, offset, period) { var target = $(id); var inst = this._getInst(target[0]); var afterAdjustDate = this._get(inst, 'afterAdjustDate'); this._oldAdjustDate(id, offset, period); if(afterAdjustDate && typeof afterAdjustDate === 'function'){ afterAdjustDate(id, offset, period); } } } $.extend($.datepicker, datepickerExtensions); })(jQuery);

And the demo: 和演示:

(html) (html)

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all"> <div class="demo"> <p>Date: <input type="text" id="datepicker"></p> </div><!-- End demo -->

(javascript) (javascript)

var changed = false; $("#datepicker").datepicker({ afterAdjustDate: function(i,o,p){ if(!changed){ $('.ui-datepicker-month').css('color', '#f00'); } changed = !changed; } });

Form this question: Proper way to add a callback to jQuery DatePicker 形成以下问题: 向jQuery DatePicker添加回调的正确方法

You can write your own extension like he did. 您可以像他一样编写自己的扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM