我有一個日期選擇器和一個形式jQuery的日期選擇器如何頁面加載後,設置默認的日期
jQuery("input[name='datepicker']" ).datepicker({ changeMonth: true, changeYear: true, dateFormat: "yy-mm-dd", altFormat:"yy-mm-dd",altField:"#stddate" });
jQuery("#qtr").change(function() {
var yr=jquery('#yeardate').val();
var qtr=jquery('#qtr').val();
if(qtr=='I'){var month=4;}
else if(qtr=='II'){var month=7;}
else if(qtr=='III'){var month=10;}
else{var month=1;}
jQuery("input[name='datepicker']").datepicker("setDate", new Date(yr,month,01));
});
下面給出的是形式
echo'<form id="change_entry" name="change_entry" >';
echo"<div align='center' id='qtrpanel'>";
echo 'Please select Year and Quarter </br>';
$dyear=2014;
$thisyear=date('Y');
$diff=$thisyear-$dyear;
echo '<select name="yeardate" id="yeardate">';
for ($i=$dyear;$i<=$thisyear;$i++){ echo'<option class="green" value="'.$i.'"';
if ($thisyear==$i) {echo 'selected';}
echo'>'.$i.'</option>'; }
echo '</select>';
echo '<select name="qtr" id="qtr"> <option value="">Select Quarter</option>
<option value="I">QTR-I</option> <option value="II">QTR-II</option> <option value="III">QTR-III</option> <option value="IV">QTR-IV</option></select></div>';
echo "<div id='fc' align='center'>Current Quarter Field Control Placed on:<input type='text' id='fc_placement' name='datepicker'/></div></br/>";
echo "<div id='tldlist' align='center'><table class='wqtable'><tr><th>TLD No</th><th>Location</th><th>Date of Removal</th><th>Dose Rate (mGy/h)</th><th>Lost</th></tr>";
while($row=mysql_fetch_array($data))
{
$rc++;
echo "<tr>";
echo "<td><input type='text' value='".$row['tldno']."'/></td>";
echo "<td>".$row['location']."</td>";
echo "<td><input type='text' id='datepicker".$rc. "'name='datepicker'/></td>";
echo "<td><input type='text' size='5' id='dose".$rc."' value='".$row2['radn_level']."'/></td>";
echo "<td><input type='checkbox' id='lost".$rc."' value='Y'/></td>";
echo "</tr>";
}
echo " </table></div>";
echo '<div align="center" >';
echo '<input id="frmsubmit" type="submit" value="Submit" width="30" />';
echo '</div>';
echo '</form>';
我想改變的默認日期根據所選年份和季度選擇日期選擇器。但它不起作用。可能是什麼問題呢?
嘗試的onChange功能「的setDate」更改爲defaultDate HTTP:// stackoverflow.com/q/14580749/4672534 – rmondesilva
是的,它使用這個jQuery(「input [name ='datepicker']」).datepicker(「option」,「defaultDate」,new Date(yeardate,month,01)); – mansoondreamz