2017-08-28 95 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/