[英]How to hide label if something is in input value
#Start+ #DITBT { position: absolute; top:5px; right:1160px; left: 15px;-webkit-transform: translate3d(0px, 0px, 0px); opacity: 0.5; transition: opacity.25s ease-in-out; -webkit-transition: opacity.25s ease-in-out; } #Start:focus + #DITBT { opacity:0; }
<div class="input-field"> <input type="text" name="firstname" id="Start" maxlength="30" class="pad" required /> <label for="Start" id="DITBT">First name</label> </div>
如果输入值中有内容,如何隐藏 label
input::placeholder { opacity: 0; } input:not(:placeholder-shown) ~ label { display: none; }
<div class="input-field"> <input type="text" placeholder="placeholder" name="firstname" id="Start" maxlength="30" class="pad" required /> <label for="Start" id="DITBT">First name</label> </div>
代替:
#Start:focus + #DITBT {
opacity:0;
}
和
#Start:focus + #DITBT {
display:none;
}
$('input').on('input',function(){
if($(this).val() != '') {
$(this).parent().find('label').fadeOut();
} else {
$(this).parent().find('label').fadeIn();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.