我使用timepicker从this websitejQuery的时间选择在多个输入字段
在我的网页有喜欢不时多个领域。我正在为此创建动态名称和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文档,但我无法弄清楚如何完成此操作?