2016-04-14 60 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