我有一个包含2个字段的表单:
<input type="text" class="datepicker" name="dateeffective" />
<input type="text" name="weekday" id="weekday" />
我想在“dateeffective”字段(即2016-01-25)输入日期后自动填写“工作日”字段(即星期一)。
我想这是用jQuery完成的......
解: 对于任何具有相同目标的人,代码都在https://jqueryui.com/datepicker/#alt-field
$(function() {
$( ".datepicker" ).datepicker({
altField: "#weekday",
altFormat: "DD"
});
});
答案 0 :(得分:1)
是的,我认为最好的方法是使用jQuery。类似的东西:
var date = $('.datepicker').datepicker('getDate');
var dayIndex= date.getUTCDay();
var weekday = new Array(7);
weekday[0]= "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var day = weekday[dayIndex];