简体   繁体   English

如何将日期显示为选择标签(仅星期几和月份中的日期)

[英]How to display a date as select tag (only day of the week and date of the month)

I am new to javascript or jQuery, I am trying to place a date picker on my website and I am able to place a datepicker with calendar, but I need it without a calendar and as a select box. 我是Java或jQuery的新手,我想在我的网站上放置一个日期选择器,并且能够将一个带有日历的日期选择器放置,但是我需要没有日历和一个选择框的日期选择器。

检查示例图片

Any idea how to do it in javascript or jQuery? 任何想法如何在javascript或jQuery中做到这一点?

Thanks 谢谢

You probably aren't going to be able to modify datepicker to do this (I will gladly concede to anyone proving otherwise), but you can easily add dates to a standard select control. 您可能无法修改datepicker来执行此操作(我很乐意向其他人承认),但是您可以轻松地将日期添加到标准的select控件中。

In this code, I have used the formatDate from the datepicker UI, so you'll need to include jQuery UI, or at least the datepicker component, for it to work. 在这段代码中,我使用了datepicker UI中的formatDate,因此您需要包括jQuery UI,或者至少包括datepicker组件,它才能正常工作。

The following example adds 10 days, starting with the current day to a select element with an ID of "mySelect". 下面的示例将从当前日期开始的10天添加到ID为“ mySelect”的select元素。

$(function () {
    var today = new Date();
    var date = new Date();

    for (x = 0; x <= 9; x++) {
        date.setDate(today.getDate() + x);
        textDate = $.datepicker.formatDate('D, dd-M', date);
        $('#mySelect')
            .append($("<option></option>")
            .attr("value", textDate)
            .text(textDate));
    }
});

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

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