How can i alert the selected days name? Example 'Monday'.
So when you pick 7th june 2011 it will alert "Tuesday"
<script>
$(function() {
$( "#date" ).datepicker({
dateFormat: 'dd/mm/yy',
onSelect: function(dateText, inst) {
// how can i grab the day name of the day, example "Monday" and alert it out?
// alert( ? );
}
});
});
</script>
How can i alert the selected days name? Example 'Monday'.
So when you pick 7th june 2011 it will alert "Tuesday"
<script>
$(function() {
$( "#date" ).datepicker({
dateFormat: 'dd/mm/yy',
onSelect: function(dateText, inst) {
// how can i grab the day name of the day, example "Monday" and alert it out?
// alert( ? );
}
});
});
</script>
Share
Improve this question
edited Nov 7, 2013 at 2:08
Tom Halladay
5,7617 gold badges50 silver badges66 bronze badges
asked Jun 25, 2011 at 21:49
KaremKarem
18.1k73 gold badges182 silver badges281 bronze badges
5 Answers
Reset to default 11The jQueryUI's Datepicker comes with a formatDate
function that can do that for you. If you're using a localized version, it'll show the days in that language too.
onSelect: function(dateText, inst) {
var date = $(this).datepicker('getDate');
alert($.datepicker.formatDate('DD', date));
}
For more information on localization of on Dapicker's utility functions, have a look at http://jqueryui.com/demos/datepicker/.
<script>
$(function() {
$( "#date" ).datepicker({
dateFormat: 'dd/mm/yy',
onSelect: function(dateText, inst) {
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
alert(weekday[inst.getDate().getDay()];
}
});
});
</script>
this will work if you don't mind showing the name of the day in the input box if you dont like it you can use second hidden input (http://jqueryui.com/demos/datepicker/#alt-field)
$(function() {
$( "#date" ).datepicker({
dateFormat: 'DD, d MM, yy',
onSelect: function(dateText, inst) {
var stop = dateText.indexOf(',');
alert( dateText.substring(0, stop));
}
});
});
example at http://jsfiddle.net/aa74R/
You can parse a date like this (mm/dd/yyyy
):
new Date(Date.parse("06/07/2011"))
and use the .getDay
function. You could do this:
// parse data
var regexp = /(\d{2})\/(\d{2})\/(\d{2})/.exec("07/06/11");
//form date
var date = new Date(Date.parse(regexp[2] + "/" + regexp[1] + "/20" + regexp[3]));
alert(date.getDay()); // 2 -> Tuesday (starts at 0 = Sunday)
Use inbuilt function
$("#datepicker" ).datepicker({ onSelect: function(dateText, inst) {
alert($.datepicker._defaults.dayNames[new Date(dateText).getDay()]);
}});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1739503770a4130335.html
评论列表(0条)