dtn55928 2016-03-08 09:53
浏览 57
已采纳

jquery datepicker如何在加载页面后设置默认日期

I have one date picker and one form

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) );    

          });

Given below is the form

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>';

I want to change the default date of the datepicker according to the year and quarter selected. But it is not working. What could be the problem?

  • 写回答

1条回答 默认 最新

  • dtncv04228 2016-03-08 10:01
    关注

    Did you check if month and year variables are setting with correct values?

    Also, month starts with 0 i.e Jan is represented with 0.

    Also, check if you have written the onChange function in document.ready

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真