我正在使用Jquery Inputmask验证用户在文本框中输入的日期。我的要求是以 mm / dd / yy 格式输入日期,但是Inputmask仅允许 mm / dd / yyyy >格式。谁能告诉我是否有一种解决方法,可以使用 mm / dd / yy 格式获得相同的结果。
编辑:问题显示为可能的重复,但我的要求是专门接受以mm / dd / yy格式显示的日期。
$("#datepicker1").datepicker({
constrainInput:"true",
dateFormat:"mm/dd/yy"
});
var maskConfig = {
leapday: "29-02-",
separator: "/",
showMaskOnHover: false,
showMaskOnFocus: false,
placeholder: "00/00/0000"
}
$('#datepicker1').inputmask('mm/dd/yyyy',maskConfig);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.3.4/jquery.inputmask.bundle.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.css">
<input type="text" id="datepicker1"/>
答案 0 :(得分:0)
var $date = $('.datepicker1');
$date.datepicker({
format: 'dd/M/yyyy',
});
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.js"></script>
<script src="https://rawgit.com/digitalBush/jquery.maskedinput/master/dist/jquery.maskedinput.min.js"></script>
<input type="text" class="datepicker1"/>
答案 1 :(得分:0)
$(".datepicker1").datepicker({
constrainInput:"true",
format:"mm/dd/yy"
});
var maskConfig = {
leapday: "29-02-",
separator: "/",
showMaskOnHover: true,
showMaskOnFocus: true,
placeholder: "00/00/00"
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.3.4/jquery.inputmask.bundle.min.js"></script>
<input type="text" class="datepicker1" data-date-format='mm/dd/yy' readonly=""/>