【发布时间】:2017-03-21 13:24:57
【问题描述】:
我正在尝试为日期选择器设置格式,但它会清除字段中的默认值。
$(".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?
所有声明现有值应与我尝试设置的日期选择器格式匹配。看起来我很干净。
谁能帮帮我?谢谢。
【问题讨论】:
-
能否在datepicker的初始化中设置日期格式而不是稍后?
标签: jquery jquery-ui jquery-ui-datepicker date-formatting