html 的input显示时间控件修改风格type=“date“ input[type=“date“]

1,594 阅读1分钟

html 的input显示时间控件修改风格

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title> 
	<style>
            /* 控制编辑区域的 */
          input[type="date"]::-webkit-datetime-edit{
            /* content: '起始时间'; */
            color: rgb(188,188,188); 
            padding-left: 10px;
          }
          /* 控制年月日这个区域的 */
          input[type="date"]::-webkit-datetime-edit-fields-wrapper { 
            background-color: #eee; 
          } 
          /* 这是控制年月日之间的斜线或短横线的 */
          input[type="date"]::-webkit-datetime-edit-text {
            color: blue; 
            padding: 0 .3em; 
          } 
          /* 控制年字 */
          input[type="date"]::-webkit-datetime-edit-year-field { 
            color: purple; 
          } 
          /* 控制月字 */
          input[type="date"]::-webkit-datetime-edit-month-field { 
            color: red; 
          } 
          /* 控制日字 */
          input[type="date"]::-webkit-datetime-edit-day-field  { 
            color: pink; 
          } 
        /*控制下拉小箭头的*/ 
        input[type="date"]::-webkit-calendar-picker-indicator {
          display: inline-block;
          width: 15px;
          height: 15px;
          /* position: absolute;
          top: 12px;
          right: 0px; */
          border: 1px solid #ccc;
          border-radius: 2px;
          box-shadow: inset 0 1px #fff, 0 1px #eee;
          background-color: #eee;
          /* background:url('../images/icon.png') -188px -99px; */
          background-image: -webkit-linear-gradient(top, #f0f0f0, #e6e6e6);
          color: #666; 
        } 
        /* 去掉date中上下小三角,但是保留input类型为number的小三角。 */
        input[type=date]::-webkit-inner-spin-button { 
          visibility: hidden; 
        }
        /*----------用来移除叉叉按钮 鼠标移上去还会显示----------*/ 
        /* input[type="date"]::-webkit-clear-button{
         display:none;
        } */
    </style>
	<script>
function displayDate(){
	var mm = document.getElementById("demo").value;
	var mm2 = document.getElementById("nowDate").value;
	var mm3 = document.getElementById("nowTime").value;
	console.log(mm,mm3,mm2)
}
</script>
</head>
	
<body>


  生日 (日期和时间): <input id="demo"  step=1 type="datetime-local" name="bdaytime" value="2015-09-24T13:59">
 <input type="date" id="nowDate" />
        <input  step=1 type="time" id="nowTime" />
<button type="button" onclick="displayDate()">点我!</button>

</body>
</html>

备注:

这个///是改不了---的,这是谷哥自带的功能样式,只能改颜色背景色等,如果要那种效果可以用日历插件

有个取巧的方法,一个不能改的input覆盖在input type="date"上面

*{

margin: 0;

padding: 0;

}

#div{

width: 500px;

height: 300px;

border: 2px solid #ccc;

position: absolute;

}

.datebox{

width: 150px;

position: relative;

height: 24px;

margin: 100px;

}

#date{

position: absolute;

left: 1px;

top: 1px;

z-index: 50;

width: 100px;

height: 100%;

height: 22px;

border: 1px solid transparent;

}

.mydate{

width: 150px;

height: 24px;

border: 1px solid #CCC;

}

function aaa(obj){

document.getElementById('date').value = obj.value;

}


#date{

position: absolute;

left: 1px;

top: 1px;

z-index: 50;

width: 100px;

height: 100%;

height: 22px;

border: 1px solid transparent;

}

.mydate{

width: 150px;

height: 24px;

border: 1px solid #CCC;

}
#date{

position: absolute;

left: 1px;

top: 1px;

z-index: 50;

width: 100px;

height: 100%;

height: 22px;

border: 1px solid transparent;

}

.mydate{

width: 150px;

height: 24px;

border: 1px solid #CCC;

}