我正在使用 Jquery 的 datepicker 插件(效果很好)。然后我需要从选择的日期中提取“星期几”。
当使用foo.substring(0,3)
分配前三个字符时,datepicker('getDate')
我得到:TypeError foo.substr is not a function
.
$(function () {
$("#textDatepicker").datepicker();
});
function selectedDay() {
var foo = $("#textDatepicker").datepicker('getDate');
//IF USED.... alert(foo);
//retuens (for example).....
//"Thu Jul 18 00:00:00 GMT-0400 (Eastern Standard Time)"
var weekday = foo.substr(0, 3)
document.getElementById("dayofweek").innerHTML = "The day of the week selected is: " + weekday;
}
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="https://jquery-blog-js.googlecode.com/files/SetCase.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"/>
</head>
<body>
Select Date: <input type="text" id="textDatepicker" onchange="selectedDay();">
<br><br>
<span id="dayofweek">Selected day of week replaces this</span>
</body>
我还粘贴在:jsfiddle
任何帮助将不胜感激..提前谢谢...