jQuery ui datepicker,从onSelect获取星期几 [英] jQuery ui datepicker, get Day of week from onSelect

查看:195
本文介绍了jQuery ui datepicker,从onSelect获取星期几的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以从dateSicker的onSelect事件中获取星期几。



我知道我可以得到一个月的日子,但是我想一周中的一天。即使只是一天的索引也会很好,例如0-6。



我知道你可以在beforeShowDay(或类似的)事件中获得它,但是我需要根据所选择的星期几做出不同的反应。
这是为了设置开放时间。



我可以打到服务器,找出来,但这不会回来够快理想情况下,我希望在客户端上完成所有操作。



Thx

解决方案

这应该是诀窍:

  function(event,ui){
var date = $(this) datepicker('getDate');
var dayOfWeek = date.getUTCDay();
};

这样做的优点是无需解析您为Datepicker文本选择的任何日期格式字段 - getDate 方法返回一个本机JavaScript Date 对象,然后您可以轻松地提取所需的日期字段。 / p>

Is it possible to get the day of the week from the onSelect event of the datepicker.

I know I can get the day of the month, but I want the day of the week. Even just the day index will be fine e.g. 0-6.

I know you can get it in the beforeShowDay (or similar) event, but I need to react differently depending on the day of the week chosen. It's to do with setting the opening times.

I could hit the server and find out, but that is not going to come back fast enough...ideally i want it all done on the client.

Thx

解决方案

This should do the trick:

function(event, ui) {
    var date = $(this).datepicker('getDate');
    var dayOfWeek = date.getUTCDay();
};

This has the advantage of not needing to parse whatever arbitrary date format you've chosen for the Datepicker's text field - the getDate method returns a native Javascript Date object which you can then easily extract the date fields you need.

这篇关于jQuery ui datepicker,从onSelect获取星期几的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆