【问题标题】:jquery ui datepicker Default Week number on loadjquery ui datepicker 默认周数加载
【发布时间】:2016-02-17 20:02:31
【问题描述】:

我得到这个工作它在主字段上的周选择“周数:#”和备用字段上得到“yy-mm-dd”

加载时,我从当前日期(今天)在两个字段上都得到“yy-mm-dd”,但我想在主要加载“周数:#”,从当前加载“yy-mm-dd”日期。

    $(function() {

    var currentDate = new Date();
    $( "#fecha" ).datepicker( {
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
       showWeek: true,
        firstDay: 1,
        dateFormat: 'yy-mm-dd',
        altField: "#date1",
        altFormat: "yy-mm-dd",

        onSelect: function(dateText, inst) {
            $(this).val("Semana Numero: " + $.datepicker.iso8601Week(new Date(dateText)));
        }


    });
     $("#fecha").datepicker("setDate", currentDate);
});

有什么建议吗?

【问题讨论】:

    标签: javascript jquery datepicker jquery-ui-datepicker


    【解决方案1】:

    我对 datepicker 插件不是很熟悉,但它似乎没有任何可以触发的事件。

    无论如何,这可能不是最好的方法,但我所做的是遍历所有日期选择器日期<a> 并触发点击与今天日期匹配的日期。

    https://jsfiddle.net/b3vstmef/

    【讨论】:

      【解决方案2】:

      我只是在查看日期选择器,看起来你不能触发 onselect,所以我发现下面的代码可以代替。

      $(function() {
         var currentDate = new Date();
         $( "#fecha" ).datepicker( {
          changeMonth: true,
          changeYear: true,
          showButtonPanel: true,
         showWeek: true,
          firstDay: 1,
          dateFormat: 'yy-mm-dd',
          altField: "#date1",
          altFormat: "yy-mm-dd",
      
          onSelect: function(dateText, inst) {
              populate(this, dateText)
          }
      
      
      });
       $("#fecha").datepicker("setDate", currentDate);
      });
      function populate(field, d){
      $(field).val("Semana Numero: " + $.datepicker.iso8601Week(new Date(d)));
      }
      
      populate($( "#fecha" ), $("#date1").val());
      

      查看实际操作: https://jsfiddle.net/y3llowjack3t/ycok5cwx/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-25
        • 1970-01-01
        • 2015-09-10
        • 2020-11-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多