【问题标题】:jquery Datepicker, set default date to value of a spanjquery Datepicker,将默认日期设置为跨度的值
【发布时间】:2012-10-29 18:12:21
【问题描述】:

如果我执行alert($(this).parents().find("span:first").html()),它会显示03/28/2011

如果我查看源代码<span id="ctl00_ContentPlaceHolder1_GridView1_ctl03_StDt">03/28/2011</span>

如果我在日期选择器中设置 defaultDate

defaultDate: new Date($(this).parents().find("span:first").html()),

默认为 1969 年 12 月 31 日

编辑 在下面vtortola的解决方案的帮助下,我明白了。我需要解析日期并检查是否有空跨度。

        var myDate = null;
        var minDate = null;
        $(".StartDateImg").datepicker({
            beforeShow: function (input, inst) {
                myDate = null;
                if ($(this).parents().find("span:first").html().length > 1) {
                    myDate = $.datepicker.parseDate("mm/dd/yy", $(this).parents().find("span:first").html());
                    $(this).parents().find("input:first").datepicker('option', 'defaultDate', myDate);

                }
                minDate = null;
                if ($(this).parents().closest('tr').find('td:last').length > 1) {
                    minDate = $.datepicker.parseDate('mm/dd/yy', $(this).parents().closest('tr').find('td:last').html())
                    $(this).parents().find("input:first").datepicker('option', 'minDate', minDate);
                }
            },
            duration: '',
            showTime: false,
            constrainInput: false,
            onSelect: function (dateText) {
                $(this).parents().find("span")[0].innerHTML = dateText;
            }

        });

【问题讨论】:

    标签: jquery date datepicker jquery-ui-datepicker


    【解决方案1】:

    试试看:

     defaultDate:  $.datepicker.parseDate('dd/mm/yy', $(this).parents().find("span:first").text())
    

    干杯。

    【讨论】:

    • 默认为当前日期。
    • $.datepicker.parseDate('dd/mm/yy',stringDate) 肯定会解析您在 stringDate 中输入的日期,因此您可能还有其他问题。您确定该 SPAN 的内容是纯文本而不是 HTML 吗?
    • 如果我查看源代码,我会看到<span id="ctl00_ContentPlaceHolder1_GridView1_ctl03_StDt">03/28/2011</span>
    • 当我现在点击它时,在日历显示之前,我得到“Microsoft JScript 运行时错误:对象不支持属性或方法'setHours'”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-12
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多