jQuery Datepicker格式,从mm-dd-yy到dd-mm-yy

时间:2015-11-15 17:00:41

标签: javascript jquery html date datepicker

正如标题所说,我想将日期选择器格式从mm-dd-yy更改为dd-mm-yy

这是我的完整代码:



$(function() {
  $('#datepicker').datepicker({
    onSelect: function(dateText, inst) {
      $("input[name='something']").val(dateText);
    }
  });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<form action="step2.php" method="post">
  <div type="text" id="datepicker" name="datepicker"></div>
  <input type="text" name="something" value="Date">
  <input type="submit" value="Submit">
</form>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

初始化datepicker时,将dateFormat属性更改为"dd-mm-yy"

默认情况下,dateFormat的值为"mm/dd/yy"。请参阅the documentation

Example Here

$('#datepicker').datepicker({
    dateFormat: "dd-mm-yy",
    onSelect: function (dateText, inst) {
        $("input[name='something']").val(dateText);
    }
});