我正在使用Jquery的datepicker插件(它工作正常)。然后我需要从采摘日期中提取“星期几”。foo.substr给出“不是函数”错误
当使用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
任何帮助,将不胜感激。在此先感谢...
为什么你同时加载的jQuery 1.9.1和1.10之前称为
toString();
方法。 2(latest.min.js)? – Sergio你是否100%确定它是一个字符串,但不是一个对象,你试图取得子串? – Jonast92
我的猜测是.substr只能用于字符串,而您正在尝试使用jQuery对象。 –