html让时间只展示年月日_如何在HTML日期输入标签中设置日期格式?

.dateField {

width: 150px;

height: 32px;

border: none;

position: absolute;

top: 32px;

left: 32px;

opacity: 0.5;

font-size: 12px;

font-weight: 300;

font-family: Arial;

opacity: 0;

}

.fakeDateField {

width: 100px; /* less, so we don't intercept click on browser chrome for date picker. could also change this at runtime */

height: 32px; /* same as above */

border: none;

position: absolute; /* position overtop the date field */

top: 32px;

left: 32px;

display: visible;

font-size: 12px; /* same as above */

font-weight: 300; /* same as above */

font-family: Arial; /* same as above */

line-height: 32px; /* for vertical centering */

}

(initial value)

var dateField = document.getElementById("dateField");

var fakeDateField = document.getElementById("fakeDateField");

fakeDateField.addEventListener("click", function() {

document.getElementById("dateField").focus();

}, false);

dateField.addEventListener("focus", function() {

fakeDateField.style.opacity = 0;

dateField.style.opacity = 1;

});

dateField.addEventListener("blur", function() {

fakeDateField.style.opacity = 1;

dateField.style.opacity = 0;

});

dateField.addEventListener("change", function() {

// this method could be replaced by momentJS stuff

if (dateField.value.length < 1) {

return;

}

var date = new Date(dateField.value);

var day = date.getUTCDate();

var month = date.getUTCMonth() + 1; //zero-based month values

fakeDateField.innerHTML = (month < 10 ? "0" : "") + month + "/" + day;

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值