SetDate Datepicker仅用于日历

时间:2016-06-17 06:21:04

标签: javascript datepicker

我使用DatePicker选择日期,并在关联的输入字段中将结果显示为周/年。点击输入文件后,我读取了值并将它们转换为日期并设置此白名setDate。这一切都很好。 但是我不希望在我的输入字段中显示转换后的日期值。只有日历应显示转换日期。这可能吗?

<div class="row no-margin-bottom">
<div class="col-lg-12">
    <div class="input-group date-group-100">
        <asp:TextBox ClientIDMode="Static" id="field1" class="form-control textbox-cursor triggerWeekPicker need-save" runat="server" />
    </div>
</div>

$('body').on('click', '.triggerWeekPicker', function () {
            var inputField = ($(this).is('input')) ? this : $(this).parent().prevAll('input.triggerWeekPicker[type=text]').first();
            if (inputField != "") {
                var inputVal = inputField.value.toString();
                if (inputVal.toString().indexOf("/") > -1) {
                    var date = calWeek(inputVal.toString().split("/")[0], inputVal.toString().split("/")[1]);
                    //var today = new Date();
                    day = date.getDay() || 7; // Get current day number, converting Sun. to 7
                    if (day !== 1)                // Only manipulate the date if it isn't Mon.
                        date.setHours(-24 * (day - 1));   // Set the hours to day number minus 1
                    //   multiplied by negative 24
                    day = date.getDate();
                    monat = date.getMonth() + 1;
                    jahr = date.getFullYear();
                }
            }

            $(inputField).datepicker({
                showOtherMonths: true,
                showCurrent: false,
                changeYear: true,
                selectOtherMonths: true,
                firstDay: 1,
                dayNamesMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
                monthNames: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
                showWeek: true,
                weekHeader: "Wo",
                dateFormat: "dd.mm.yy",
                showOn: "focus",
                onSelect: function (dateText, inst) {
                    var date = $(this).datepicker('getDate');
                    $(inputField).val($.datepicker.iso8601Week(date) + "/" + date.getFullYear());
                    $(inputField).change();
                },
                beforeShow: function () {
                    setTimeout(function () {
                        $('.ui-datepicker').css('z-index', 10);
                    }, 0);
                    if (monat != "" && jahr != "") {
                        var dateSet = new Date(jahr, monat - 1, day);
                        $(this).datepicker().datepicker("setDate", dateSet);
                        monat = "";
                        jahr = "";
                    }
                }
            }).focus();

0 个答案:

没有答案