2017-08-28 13 views
-1

我有一個HTML表單,它預載了來自MySQL的數據。我添加了一個表單字段「New Follow Up」,使用datepicker有一個彈出日曆。 datepicker返回一個DATE格式,我需要將它轉換爲MySQL的DATETIME。目前回報爲date_followupPHP的HTML表單和Java的日期選擇器

我想知道這是否可以在<script>函數內完成,以便date_followup可以採用標準的DATETIME格式,從而消除轉換。還是有更簡單的方法?

<div class="control-group <?php echo !empty($date_followupError)?'error':'';?>"> 
    <label class="control-label">New Followup Date</label> 
    <div class="controls"> 
     <input name="date_followup" type="text" placeholder="Enter Follow up date" value="<?php echo !empty($date_followup)?$date_followup:'';?>"> 
     <?php if (!empty($date_followupError)): ?> 
     <span class="help-inline"><?php echo $date_followupError;?></span> 
     <?php endif;?> 

     <head> 
      <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> 
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
      <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> 
      <script> 
       $(document).ready(function() { 
        $("#datepicker").datepicker(); 
       }); 
      </script> 
     </head> 

     <body> 
      <input id="datepicker" input name="date_followup"> 
     </body> 
    </div> 
</div> 

回答

0

首先,我建議你分割你的代碼。創建您自己的JavaScript文件,例如main.js,編寫您的所有JavaScript函數並引用HTML-header中的main.js文件。調試你的代碼會容易得多。此外,您需要JavaScrip-Lib作爲Datetimepicker。正如我以前的發言人所說的,使用eonasdan-picker並在頭文件中也引用它。所以:

HTML

<head> 
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> 
    <script type="text/javascript" src="https://github.com/Eonasdan/bootstrap-datetimepicker/blob/master/src/js/bootstrap-datetimepicker.js"></script> 
    <script type="text/javascript" src="path/to/main.js"></script> 
</head> 
<body> 
    <div class="form-group"> 
    <div class='input-group date' id='datepicker'> 
     <input type='text' class="form-control" /> 
     <span class="input-group-addon"> 
     <span class="glyphicon glyphicon-calendar"></span> 
     </span> 
    </div> 
    </div> 
</body> 

的JavaScript(main.js)

$(document).ready(function() { 
    $('#datepicker').datetimepicker({ 
     //here you have the possibilty to configure the picker as you wish 
     //e.g. the format 
     format: 'y-m-d' 
     //read the documentary of EONASDAN to see which attributes you can choose 
    }) 
}); 

重要:你CSS-和JS-利布斯事項的順序。例如。 EONASDAN的datetimepicker需要jQuery-Lib。如果jQuery-lib在eonasdan之後被修改,它將無法工作。與main.js一樣,它應該將加密作爲最後一個文件。

0
**include bootstrap files** 

<div class="container"> 
    <div class="row"> 
     <div class='col-sm-6'> 
      <div class="form-group"> 
       <div class='input-group date' id='datetimepicker1'> 
        <input type='text' class="form-control" /> 
        <span class="input-group-addon"> 
         <span class="glyphicon glyphicon-calendar"></span> 
        </span> 
       </div> 
      </div> 
     </div> 
     <script type="text/javascript"> 
      $(function() { 
       $('#datetimepicker1').datetimepicker(); 
      }); 
     </script> 
    </div> 
</div> 

https://eonasdan.github.io/bootstrap-datetimepicker/ 
相關問題