选择日期选择日期后的jquery

时间:2014-05-09 15:23:28

标签: jquery datepicker

我在jQuery中并不强大,所以有这种情况。

我有代码

.datetimepicker({
onSelectDate:function(current_time,$input){
alert(current.dateFormat('d/m/Y')
}

同样以相同的形式我选择了day元素:

<select size="1" name="lessonday">
<option value="monday">monday</option>
<option value="tuedsay">tuedsay</option>
</select>

所以我希望在日期选择后动态选择这种形式的日子。如何制作?

我使用jQuery Date Time Picker插件进行日期选择。

1 个答案:

答案 0 :(得分:0)

如果您可以更改&lt;选项&gt; value属性使用代表每一天的数字(即0 =星期日,1 =星期一等)然后你可以这样做:

HTML:

<select size="1" name="lessonday" id="lessonDay">
  <option value="0">sunday</option>
  <option value="1">monday</option>
  <option value="2">tuedsay</option>
  <option value="3">wednesday</option>
  <option value="4">thursday</option>
  <option value="5">friday</option>
  <option value="6">saturday</option>
</select>

JS:

.datetimepicker({
    onSelectDate:function(selectedDateTime,$input){
        $('#lessonDay').val(selectedDateTime.getDay());
    }
});

如果您无法更改&lt;选项&gt;上的值属性标签,您需要一个数组来将.getDay()值映射到星期几的名称:

HTML:

<select size="1" name="lessonday" id="lessonDay">
  <option value="sunday">sunday</option>
  <option value="monday">monday</option>
  <option value="tuedsay">tuedsay</option>
  <option value="wednesday">wednesday</option>
  <option value="thursday">thursday</option>
  <option value="friday">friday</option>
  <option value="saturday">saturday</option>
</select>

JS:

var dayOfWeek = new Array(7);
dayOfWeek[0]=  "sunday";
dayOfWeek[1] = "monday";
dayOfWeek[2] = "tuesday";
dayOfWeek[3] = "wednesday";
dayOfWeek[4] = "thursday";
dayOfWeek[5] = "friday";
dayOfWeek[6] = "saturday";

.datetimepicker({
    onSelectDate:function(selectedDateTime,$input){
        $('#lessonDay').val(dayOfWeek[selectedDateTime.getDay()]);
    }
});