gpt4 book ai didi

javascript - 如何在一个字母后输入无效

转载 作者:可可西里 更新时间:2023-11-01 15:00:16 24 4
gpt4 key购买 nike

H-I

这是我的输入

.centered-name 
{
width: 80%;
margin: auto;
}
.group {
width: 100%;
overflow: hidden;
position: relative;
}
.label {
position: absolute;
top: 40px;
color: #666666;
font: 400 26px Roboto;
cursor: text;
transition: 0.3s ease;
width: 100%;
text-align: center;
}

.input {
display: block;
width: 100%;
padding-top: 36px;
border: none;
border-radius: 0;
font-size: 30px;
transition: .3s ease;
text-align: center;
}
.input:valid ~ .label
{
top: 3px;
font: 400 26px Roboto;
}


.input:focus {
outline: none;
}
.input:focus ~ .label {
top: 3px;
font: 400 26px Roboto;
}
.input:focus ~ .bar:before {
transform: translateX(0);
}
.bar {
border-bottom: 2px solid #ff5126;
width: 100%;
margin-top: 6px;
transition: .3s ease;
}
.input:valid ~ .bar
{
border-bottom: 2px solid #3bb873;
}
<div class="centered-name">
<div class="group">
<input type="text" minlength="5" dir="rtl" class="input res" id="name" required autocomplete="off" />
<label class="label res" for="name">Name</label>
<div class="bar"></div>
</div>
</div>

当无效并且你写了一些东西(少于 5 个字母)并且它失去了焦点,标签下降了

我也试试

.input:invalid ~ .label 
{
top: 3px;
font: 400 26px Roboto;
}

.centered-name
{
width: 80%;
margin: auto;
}
.group {
width: 100%;
overflow: hidden;
position: relative;
}
.label {
position: absolute;
top: 40px;
color: #666666;
font: 400 26px Roboto;
cursor: text;
transition: 0.3s ease;
width: 100%;
text-align: center;
}

.input {
display: block;
width: 100%;
padding-top: 36px;
border: none;
border-radius: 0;
font-size: 30px;
transition: .3s ease;
text-align: center;
}
.input:valid ~ .label
{
top: 3px;
font: 400 26px Roboto;
}
.input:invalid ~ .label
{
top: 3px;
font: 400 26px Roboto;
}

.input:focus {
outline: none;
}
.input:focus ~ .label {
top: 3px;
font: 400 26px Roboto;
}
.input:focus ~ .bar:before {
transform: translateX(0);
}
.bar {
border-bottom: 2px solid #ff5126;
width: 100%;
margin-top: 6px;
transition: .3s ease;
}
.input:valid ~ .bar
{
border-bottom: 2px solid #3bb873;
}
<div class="centered-name">
<div class="group">
<input type="text" minlength="5" dir="rtl" class="input res" id="name" required autocomplete="off" />
<label class="label res" for="name">Name</label>
<div class="bar"></div>
</div>
</div>

但是在我们写任何东西之前标签又上升了

写信后输入无效怎么办?

最佳答案

试试这个..添加下面的js

$('#name').keyup( function() {
if( this.value.length < 6 ) {
$('input').blur();
}
});
.centered-name 
{
width: 80%;
margin: auto;
}
.group {
width: 100%;
overflow: hidden;
position: relative;
}
.label {
position: absolute;
top: 40px;
color: #666666;
font: 400 26px Roboto;
cursor: text;
transition: 0.3s ease;
width: 100%;
text-align: center;
}

.input {
display: block;
width: 100%;
padding-top: 36px;
border: none;
border-radius: 0;
font-size: 30px;
transition: .3s ease;
text-align: center;
}
.input:valid ~ .label
{
top: 3px;
font: 400 26px Roboto;
}


.input:focus {
outline: none;
}
.input:focus ~ .label {
top: 3px;
font: 400 26px Roboto;
}
.input:focus ~ .bar:before {
transform: translateX(0);
}
.bar {
border-bottom: 2px solid #ff5126;
width: 100%;
margin-top: 6px;
transition: .3s ease;
}
.input:valid ~ .bar
{
border-bottom: 2px solid #3bb873;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="centered-name">
<div class="group">
<input type="text" minlength="5" dir="rtl" class="input res" id="name" required autocomplete="off" />
<label class="label res" for="name">Name</label>
<div class="bar"></div>
</div>

</div>

关于javascript - 如何在一个字母后输入无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53334004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com