2017-03-21 38 views
0

日付選択ツールの書式を設定しようとしていますが、項目のデフォルト値がクリアされています。設定JQuery日付ピッカーの日付書式が初期日付値を消去します

$(".date").datepicker(); 
 
// While trying to format (the same format as mentioned above 'dd-mm-yy'), the field value is cleared on execution of below code 
 
$('.date').datepicker("option", "dateFormat", "dd-mm-yy");
<html> 
 

 
<head> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
 
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> 
 
</head> 
 

 
<body> 
 
    <!-- Kindly note that format of the value here is 'dd-mm-yy' --> 
 
    <p>Date: <input class='date' type="text" value="31-12-2016"></p> 
 
</body> 
 

 
</html>

すでに私はこれらの記事 を読んでいます| JQuery UI Datepicker date format issue with initial value | Why does constructing a JQuery UI Datepicker clear the field's value? | Setting 'option' on jqueryui DatePicker clears the textbox's value?

既存の値は、設定しようとしている日付ピッカーの形式と一致する必要があります。私はそれがきれいだと思われる。

誰でもお手伝いできますか?ありがとう。

+1

に光を投げるため

@Twistyおかげで後で日付ピッカーの初期設定で日付形式を設定する代わりにもらえますか? – Twisty

答えて

0

その作業中! datepickerの初期化時に日付書式を設定しました。これでデフォルト値が保持され、日付書式も機能します。この

//Setting the format on initialisation 
 
$(".date").datepicker({ dateFormat: 'dd-mm-yy' }); 
 

 
// While trying to format (the same format as mentioned above 'dd-mm-yy'), the field value is cleared on execution of below code 
 

 
//$('.date').datepicker("option", "dateFormat", "dd-mm-yy");
<html> 
 

 
<head> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
 
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> 
 
</head> 
 

 
<body> 
 
    <!-- Kindly note that format of the value here is 'dd-mm-yy' --> 
 
    <p>Date: <input class='date' type="text" value="31-12-2016"></p> 
 
</body> 
 

 
</html>

関連する問題