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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog