4
我有一个页面,其中有多个来自date和todate的输入字段。我创建了动态ID和名称。我用jQuery日期选择器。在多个输入字段上的jquery日期选择器
代码:
<?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代码对于日期选取器:
(document).ready(function(){
var count=0;
count=<?php echo count($locations);?>;
for(i=1;i<=count;i++)
{
var dates = $('#txtFromDate_'+i+', #txtToDate_'+i).datepicker({
defaultDate: new Date(),
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd',
onSelect: function(selectedDate) {
var option = this.id == "txtFromDate_"+i ? "maxDate" : "minDate";
var instance = $(this).data("datepicker");
var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
});
}
jQuery的日期选取器显示没有fromdate和日期字段。在上面的代码中,我已经应用了从日期到日期验证,即到日期应该大于从日期开始。
上述代码的问题在于,此验证仅应用于最后一行。
我想这个验证应该适用于所有的行。
感谢wtk的回复。你能否详细说明你的答案? –
我已经应用了建议的代码,但它迄今为止没有工作的日期可以选择少于日期。 –
对不起。还有一个错误 - 我更新了代码。 – WTK