为 JQuery 日期选择器设置日期格式会清除初始日期值
Setting Date format for JQuery date picker clears the initial date value
我正在尝试为日期选择器设置格式,但它清除了字段中的默认值。
$(".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?
所有声明现有值应与我尝试设置的日期选择器格式相匹配。看起来我很干净。
谁能帮帮我?谢谢
它的工作!我在日期选择器的初始化时设置了日期格式。现在保留默认值,日期格式也有效。
@Twisty 感谢您对此进行说明
//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>
我正在尝试为日期选择器设置格式,但它清除了字段中的默认值。
$(".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?
所有声明现有值应与我尝试设置的日期选择器格式相匹配。看起来我很干净。
谁能帮帮我?谢谢
它的工作!我在日期选择器的初始化时设置了日期格式。现在保留默认值,日期格式也有效。
@Twisty 感谢您对此进行说明
//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>