Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery datepicker返回周数和星期几_Javascript_Jquery_Jquery Ui_Jquery Ui Datepicker - Fatal编程技术网

Javascript JQuery datepicker返回周数和星期几

Javascript JQuery datepicker返回周数和星期几,javascript,jquery,jquery-ui,jquery-ui-datepicker,Javascript,Jquery,Jquery Ui,Jquery Ui Datepicker,我试图通过JQuery日历根据所选日期获取工作日的工作日编号和名称/快捷方式。 我不是真的精通JQuery,所以我可以得到周数,但我似乎无法用它来获得当天的名称 有人能帮我吗 $('#datepicker').datepicker({ onSelect: function (dateText, inst) { $('#weekNumber').val($.datepicker.iso8601Week(new Date(dateText))); } }); 您

我试图通过JQuery日历根据所选日期获取工作日的工作日编号和名称/快捷方式。 我不是真的精通JQuery,所以我可以得到周数,但我似乎无法用它来获得当天的名称

有人能帮我吗

  $('#datepicker').datepicker({
    onSelect: function (dateText, inst) {
        $('#weekNumber').val($.datepicker.iso8601Week(new Date(dateText)));
    }
});

您必须获取日期,然后从中提取日期的名称:

      var date = $(this).datepicker('getDate');
      alert($.datepicker.formatDate('DD', date));
希望有帮助


编辑:您可以找到工作小提琴。

您可以使用datepicker文档中的格式日期语法,在现有块中添加日期名称,如下所示:

在本例中,全天名称是从“DD”中获取的,因此更新后的代码可能如下所示:

$('#datepicker').datepicker({
    onSelect: function (dateText, inst) {
        var d = new Date(dateText);
        $('#weekNumber').val($.datepicker.iso8601Week(d));
        $('#dayName').val($.datepicker.formatDate('DD', d));
    }
});

这里有很多关于如何使用javascript日期对象的信息

以下是我建议您使用的代码:

 $(function() {
        $( "#datepicker" ).datepicker({
            onSelect: function( dateText, dateObj ){
            //You can get your date string that way
            console.log(dateText);

            //You can get a few value about the date, look in your console to see what you can do with that object
            //i.e. - console.log(dateObj.selectedDay)
            console.log(dateObj);

           //You can see the result of the date in string that way
           $('.string').append(dateText);

           currDate = new Date(dateText);
           //You can have a complete Date object using the Date javascript method
           console.log(currDate);

           //The Date object in javascript provides you all you need then

          //Get the number of day in a week, from 0(Sunday) to 6(Saturday)
          $('.getday').append(currDate.getDay());

         //Create a function to see day Sun - Sat
         function getWeekDay(date) {
           var days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
           return days[ date.getDay() ]
         } 
         //Then we use it
         $('.getweekday').append(getWeekDay(currDate));
    }
   });
 });
你可以在那里看到我的小提琴:

这是一个很好的信息来源,您也可以使用Date对象:

谢谢你,伙计,现在好像工作了!我是js新手,所以这真的很有帮助,不客气!如果您觉得这很有用,请接受答案:)