如何使 DatePicker 中的日期不可选择?

发布于 2025-01-07 23:28:01 字数 189 浏览 7 评论 0原文

我在想如何只启用一周中的某些天?例如如何使某月某一周的周一、周三、周四启用,其余日期禁用?

我已经尝试过 setDate(DateOption dateOption) 、 setMaxDate(DateOption dateOption) 和 setMinDate(DateOption dateOption) 但没有结果。

谢谢。

I was wandering how to make only some days in a week enabled? For example how to make Monday Wednesday and Thursday enabled and the rest of the days disabled in a certain week in a certain month?

I have played around with setDate(DateOption dateOption), setMaxDate(DateOption dateOption), and setMinDate(DateOption dateOption) but with no result.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半衾梦 2025-01-14 23:28:01

AFAIK 你不能用默认的 jQuery 日期选择器来做到这一点。

我最近自己遇到了这个问题,我无法使用默认的 jQuery datepicker 找到解决方案,所以我使用以下方法创建了自己的 wiQuery 插件: http://keith-wood.name/datepick.html。它需要更多的工作,但是通过深入研究 wiQuery 代码,您可以找到需要模拟的类来让这个备用日期选择器工作。

  • 复制了: DatePickerOptions
  • DatePicker
  • DatePickerJavascriptResourceReference
  • JsScopeUiDatePickerOnChange

从 org.odlabs.wiquery.ui.datepicker

.classes。我将“Multi”附加到这些类名的开头,并使用了设置和回调选项的参考指南: http://keith-wood.name/datepickRef.html(也可以通过单击第一个链接中的快速参考来查看更简洁但不太简洁的版本),使我新创建的 MultiDatePicker 类能够生成正确的 javascript。

例如,默认情况下,DatePicker 中有以下代码:

public JsStatement statement() {
    return new JsQuery(this).$().chain("datepicker",
            options.getOptions().getJavaScriptOptions());
}

用于创建以下 javascript:

(function($) {
$(document).ready(function() {$('#startDate').datepicker({defaultDate: '+1', minDate: '+1', showOn: 'both', buttonImageOnly: true, buttonImage: '/Calendar.png'});
});
})(jQuery);

(其中我选择的选项位于大括号内)。

我在 MultiDatePicker.java 中将其更改为:

public JsStatement statement()
{
    return new JsQuery(this).$().chain("datepick", options.getOptions().getJavaScriptOptions());
}

我将以下行:

public void setMultiSelect(int i)
{
    put("multiSelect", i);
}

public int getMultiSelect()
{
    return getInt("multiSelect");
}

放入我的 multiDatePickerOptions 中,并在 MultiDatePicker 类中设置了一些愚蠢的 getter 和 setter 来设置这些选项,这允许您设置可以设置多少个日期。通过完成所有这些,我能够做到:

MultiDatePicker multiDatePicker = new MultiDatePicker("datePicker");
multiDatePicker.setMultiSelect(2);
add(multiDatePicker);

生成以下 javascript 代码:

$('#startDate').datepick({multiSelect: 999, showTrigger: '/Calendar.png', dateFormat: 'dd/mm/yyyy', onDate: function(date, current) { /*I used this callback function to only allow certain dates to be selected by the user.*/}});

祝你好运!

AFAIK you cannot do this with the default jQuery datepicker.

I recently came across this problem myself, I could not find a solution using the default jQuery datepicker, so instead I created my own wiQuery plugin using: http://keith-wood.name/datepick.html. It requires a little more work, but by digging into the wiQuery code, you can find the classes you need to emulate to get this alternate datepicker working.

I copied the:

  • DatePickerOptions
  • DatePicker
  • DatePickerJavascriptResourceReference
  • JsScopeUiDatePickerOnChange

.classes from org.odlabs.wiquery.ui.datepicker.

I appended 'Multi' to the beginning of these class-names and used the reference guide of settings and callback options at: http://keith-wood.name/datepickRef.html (can also see a neater but less concise version by clicking quick ref from the first link) to enable my newly created MultiDatePicker class to generate the correct javascript.

For example, by default in DatePicker there is the following code:

public JsStatement statement() {
    return new JsQuery(this).$().chain("datepicker",
            options.getOptions().getJavaScriptOptions());
}

Which is used to create the following javascript:

(function($) {
$(document).ready(function() {$('#startDate').datepicker({defaultDate: '+1', minDate: '+1', showOn: 'both', buttonImageOnly: true, buttonImage: '/Calendar.png'});
});
})(jQuery);

(where my chosen options are within the curly braces).

I changed this in my MultiDatePicker.java to:

public JsStatement statement()
{
    return new JsQuery(this).$().chain("datepick", options.getOptions().getJavaScriptOptions());
}

I placed the lines:

public void setMultiSelect(int i)
{
    put("multiSelect", i);
}

public int getMultiSelect()
{
    return getInt("multiSelect");
}

into my multiDatePickerOptions, and some dumb getters and setters in the MultiDatePicker class which set these options, and this allows you to set how many dates can be set. By doing all this I was then able to do:

MultiDatePicker multiDatePicker = new MultiDatePicker("datePicker");
multiDatePicker.setMultiSelect(2);
add(multiDatePicker);

Which generates the following javascript code:

$('#startDate').datepick({multiSelect: 999, showTrigger: '/Calendar.png', dateFormat: 'dd/mm/yyyy', onDate: function(date, current) { /*I used this callback function to only allow certain dates to be selected by the user.*/}});

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文