2016-04-14 108 views
1

因此,经过反复试验,我终于按照自己喜欢的方式运行了日历。我只允许选择某个时间段。无论当前日期是10天还是21天,都可以。不过,我将这个新日历插入另一个预先安装的日历的插槽中,并且我需要确保将值正确传递到MySQL,这取决于它之前的设置。JavaScript to JQuery; MySQL的格式化日期

以前存在的代码是JavaScript,我将其更改为JQuery。上面的代码有这一行吧:

dateFormat: 'yy-mm-dd' // MySQL datetime format 

现在,我想的如果可能的话我的新日历相同的日期格式。

$(document).ready(function() { 
 
    $('.txtDeadline').datepicker({ minDate: +10, maxDate: +21 }); 
 
    }); 
 

 

 
// Still needs dateFormat: 'yy-mm-dd' for MySQL datetime format
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
 
<head> 
 
<link href="//code.jquery.com/ui/1.9.2/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" /> 
 
<script src="//code.jquery.com/jquery-1.8.3.min.js"></script> 
 
<script src="//code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 
 
</head> 
 

 

 

 
<div class="clear"> 
 
\t <label for="txtDeadline">Deadline<span class="required">*</span></label> 
 
\t <div class="input"> 
 
\t \t <input class="txtDeadline" name="txtDeadline" type="text" /> 
 
\t \t <p>Min: 10 days Max: 21 days from current date</p> 
 
\t </div> 
 
</div>

回答

0

$(document).ready(function() { 
 
    $('.txtDeadline').datepicker({ minDate: +10, maxDate: +21,dateFormat: 'yy-mm-dd' }); 
 
    }); 
 

 

 
// Still needs dateFormat: 'yy-mm-dd' for MySQL datetime format
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
 
<head> 
 
<link href="//code.jquery.com/ui/1.9.2/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" /> 
 
<script src="//code.jquery.com/jquery-1.8.3.min.js"></script> 
 
<script src="//code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 
 
</head> 
 

 

 

 
<div class="clear"> 
 
\t <label for="txtDeadline">Deadline<span class="required">*</span></label> 
 
\t <div class="input"> 
 
\t \t <input class="txtDeadline" name="txtDeadline" type="text" /> 
 
\t \t <p>Min: 10 days Max: 21 days from current date</p> 
 
\t </div> 
 
</div>

+0

非常感谢帮助我! – wingchunnt

+0

我很乐意帮助你 – DK3