input[type="date"]::-webkit-calendar-picker-indicator { position : relative ; left : -120px ; background-image : url ( "../assets/img/submitInfo/日期选择器.png" ) ;
  1. 隐藏年月日,显示placeholder
input[type="date"]:before {
  content: attr(placeholder);
  padding-left: 20px;

在这里插入图片描述
可以看到此时还有如下问题,placeholder成功显示,但是此时默认的年月日还在显示

  1. 当选择日期后,placeholder隐藏,默认日期格式显示
input[type="date"].selected:before  {
  content: "" !important;
  let itemRightDate = document.querySelector("input[type=date][name=date]");
   itemRightDate.addEventListener("input", function (e) {
    let {
      target: { value },
    } = e;
    if (value.length > 0) {
      e.target.classList.add("selected");
    } else {
      e.target.classList.remove("selected");
  });
  1. 针对placeholder显示时默认的年月日显示且被截断
input[type="date"]::-webkit-datetime-edit-year-field {
  position: relative;
  left: 10px;

在这里插入图片描述
5. placeholder样式和设计稿不符

input[type="date"]:before {
  content: attr(placeholder);
  padding-left: 20px;
  color: var(--gray-rgba-116116116);
  font-size: 16px;
  line-height: 22px;

在这里插入图片描述
可以看到已经满足要求了,录区域视频再转gif太麻烦了,截图也能表现出来~

  1. 最终完整版样式
input[type="date"] {
  display: flex;
  padding-left: 10px;
  padding-right: 550px;
  font-size: 16px;
  line-height: 24px;
input[type="date"]:before {
  content: attr(placeholder);
  padding-left: 20px;
  color: var(--gray-rgba-116116116);
  font-size: 16px;
  line-height: 22px;
input[type="date"].selected:before  {
  content: "" !important;
input[type="date"]::-webkit-datetime-edit-year-field {
  position: relative;
  left: 10px;
input[type="date"]::-webkit-calendar-picker-indicator {
  position: relative;
  left: -120px;
  background-image: url("../assets/img/submitInfo/日期选择器.png");
                    项目场景:如图,需求方要求input框的日期选择器修改成如下格式,默认样式如底部解决方案:以下为修改步骤:替换日期选择器icon,并将其移到左边input[type="date"] {  display: flex;  padding-left: 10px;  padding-right: 550px;  font-size: 16px;  line-height: 24px;}input[type="date"]::-webkit-calendar-picker-
				
1、placeholder 问题解决方法 对 input type date 使用 placeholder 的目的是为了让用户更准确的输入日期格式,iOS 上会有 date 不会显示 placeholder 文字,但是为了统一表单外观,往往需要显示。Android 部分机型没有 date 也不会显示 placeholder 文字。 解决方法: 先使其 type 为 text,此时支持 pla...
var date = new Date(); var day = ("0" + date.getDate()).slice(-2); var month = ("0" + (date.getMonth() + 1)).slice(-2); //拼接成yyyy-MM- <div class="form-group"> <label for="date">参观日期日期</label> <input type="date" class="form-control" id="date" placeholder="选择你有空的时间" onchange="dateAstrict(this)"> <small id="da