在JQuery UI datepicker中选择周数或日期 [英] Select week number or date in JQuery UI datepicker
本文介绍了在JQuery UI datepicker中选择周数或日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我第一次使用jQuery UI做一些事情,而且我的JS技能也是初学者级别。
This is the first time that I do something with jQuery UI and also my JS skills are at the beginner level.
我的问题是什么:
我想使用JQuery UI datepicker来选择:
I wanna use JQuery UI datepicker to select:
- 单击一个日期day
或 - 当我点击周号时,获取日期范围。
如何获取日期/日期范围?但是,要获得一个简单的工作示例是很好的。
How can I get the date/date range? But it would be nice to get a simple working example.
推荐答案
也许这样会帮助你:
$( "#datepicker" ).datepicker({
showWeek: true,
firstDay: 1
});
// Highlight week on hover week number
$(document).on("mouseenter",".ui-datepicker-week-col",
function(){$(this).siblings().find("a").addClass('ui-state-hover');} );
$(document).on("mouseleave",".ui-datepicker-week-col",
function(){$(this).siblings().find("a").removeClass('ui-state-hover');} );
// Select week on click on week number
$(document).on("click",".ui-datepicker-week-col",
function(){
$first = $(this).siblings().find("a").first();
$last = $(this).siblings().find("a").last();
$first.click();
$parentFirst = $first.parent();
$parentLast = $last.parent();
$("#datepicker").val(
(Number($parentFirst.data("month"))+1)+"/"+$first.text()+"/"+$parentFirst.data("year")
+ " - " +
(Number($parentLast.data("month"))+1)+"/"+$last.text()+"/"+$parentLast.data("year")
);
});
小提琴演示: http://jsfiddle.net/lparcerisa/hw1tpthb/3/
这篇关于在JQuery UI datepicker中选择周数或日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文