我正在使用这个网站上的时间选择器
在我的页面中,不时有多个字段。我正在为此创建动态名称和 ID。
PHP代码:
<?php
$i=1;
foreach($locations as $location)
{
?>
<tr>
<td><?php echo $location['name'];?>
</td>
<td>
<input type="text" name="txtFromDate_<?php echo $location['pk_locationid'];?>" class="field" style="width:80px;" id="txtFromDate_<?php echo $i;?>"/>
</td>
<td>
<input type="text" name="txtToDate_<?php echo $location['pk_locationid'];?>" class="field" style="width:80px;" id="txtToDate_<?php echo $i;?>"/>
</td>
<td>
<input type="text" name="txtFromTime_<?php echo $location['pk_locationid'];?>" class="time-pick field" style="width:80px;" />
</td>
<td>
<input type="text" name="txtToTime_<?php echo $location['pk_locationid'];?>" class="time-pick field" style="width:80px;"/>
</td>
</tr>
<?php
$i++;
}
?>
jQuery代码:
<script type="text/javascript">
$(document).ready(function(){
var count=0;
count=<?php echo count($locations);?>;
for(i=1;i<=count;i++)
{
(function(i) {
$('#txtFromDate_'+i+', #txtToDate_'+i).datepicker({
defaultDate: new Date(),
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy',
onSelect: function(selectedDate) {
var option, otherPicker;
if (this.id == "txtFromDate_"+i) {
otherPicker = $("#txtToDate_"+i);
option = "minDate";
} else {
otherPicker = $("#txtFromDate_"+i);
option = "maxDate";
}
var instance = $(this).data("datepicker");
var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
otherPicker.datepicker("option", option, date);
}
});
})(i);
}
$('.time-pick').timepicker({});
$("#frmSubmitArtwork").validate({
errorClass: 'jqueryError',
validClass: 'jqueryValid',
errorElement: 'label',
success: 'jqueryValid',
messages: {
txtTitle: {
required: 'Please enter title'
},
cmbType: {
required: 'Please choose type',
},
txtDescription: {
required: 'Please enter description'
}
}
});
});
</script>
我希望时间应该总是大于从时间,就像我对 fromdate 和 todate 字段所做的那样。datepicker 文档中有 fromdate 和 todate 验证的示例,但我已阅读 timepicker 文档,但我无法弄清楚如何完成此操作?