是否存在与之等效的CSS代码
::-webkit-datetime-edit
::-webkit-datetime-edit-fields-wrapper
::-webkit-datetime-edit-text
::-webkit-datetime-edit-month-field
::-webkit-datetime-edit-day-field
::-webkit-datetime-edit-year-field
::-webkit-inner-spin-button
::-webkit-calendar-picker-indicator
对于Firefox和Microsoft Edge?到目前为止,我找不到与<input type='date'>
的占位符样式有关的任何文档/资源。任何建议/答案表示赞赏。
尝试了::placeholder
,::-ms-input-placeholder
和::-moz-placeholder
,但是当输入类型为日期时它们不起作用。
或者,如果有人可以告诉我如何隐藏默认占位符,我很乐意接受答案。
答案 0 :(得分:0)
通过使用F12开发人员工具检查HTML和CSS,我们可以看到使用用户代理sytelsheet和这些伪元素(::-webkit)的Chrome浏览器适用于chrome浏览器,但是在Microsoft Edge浏览器中,它没有使用用户代理sytelsheet,并且这些伪元素不会应用于输入日期文本框。因此,该代码在Microsoft Edge中不起作用。
因此,我认为您可以尝试使用Microsoft Edge Dev版本(基于铬),代码可以很好地工作。
否则,作为一种解决方法,建议您参考以下代码以使用文本框和datepicker插件显示日期。
<style>
.input-field {
position: relative;
display: inline-block;
}
.input-field > label {
position: absolute;
left: 0.5em;
top: 50%;
margin-top: -0.5em;
opacity: 0.5;
}
.input-field > input[type=text]:focus + label {
display: none;
}
.input-field > label > span {
letter-spacing: -2px;
}
.month {
color: cornflowerblue;
}
.day {
color: aqua;
}
.year {
color:darkmagenta
}
.separate-letter {
color: red
}
</style>
<link href="http://code.jquery.com/ui/1.9.2/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<div class="input-field">
<input id="input-text-field" type="text" class="date" data-selecteddate="" value="" />
<label for="input-text-field">
<span id="span_month" class="month">MM</span>
<span class="separate-letter">/</span>
<span id="span_day" class="day">DD</span>
<span class="separate-letter">/</span>
<span id="span_year" class="year">YYYY</span>
</label>
</div>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script>
$(function ($) {
$(".date").datepicker({
onSelect: function (dateText) {
//display("Selected date: " + dateText + "; input's current value: " + this.value);
var dataarray = dateText.split("/")
$("#span_month").html(dataarray[0]);
$("#span_day").html(dataarray[1]);
$("#span_year").html(dataarray[2]);
//clear the textbox value
this.value = "";
$("#input-text-field").attr("data-selecteddate", dateText);
}
})
});
</script>
这样的结果(使用Microsoft Edge浏览器):