我想在输入字段中将日期格式mm/dd/yyyy更改为dd/mm/yyyy。
我的输入字段:
<input type="date">
Run Code Online (Sandbox Code Playgroud)
除了使用 CSS 和 js 之外,没有办法更改默认的日期类型输入
$("input").on("change", function() {
this.setAttribute(
"data-date",
moment(this.value, "YYYY-MM-DD")
.format( this.getAttribute("data-date-format") )
)
}).trigger("change")Run Code Online (Sandbox Code Playgroud)
input {
position: relative;
width: 150px; height: 20px;
color: white;
}
input:before {
position: absolute;
top: 3px; left: 3px;
content: attr(data-date);
display: inline-block;
color: black;
}
input::-webkit-datetime-edit, input::-webkit-inner-spin-button, input::-webkit-clear-button {
display: none;
}
input::-webkit-calendar-picker-indicator {
position: absolute;
top: 3px;
right: 0;
color: black;
opacity: 1;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
<input type="date" data-date="" data-date-format="DD/MM/YYYY" value="2020-08-29">Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
57787 次 |
| 最近记录: |