javascript - 当我自动完成输入字段时,值被标签覆盖并且在加载时也没有获得长度

标签 javascript jquery html css node.js

当我填写表格并保存然后刷新时,出现以下问题。

当我自动保存输入字段时,值被标签覆盖并且在加载时也没有获得长度。我已经尝试过并在谷歌上进行了很多搜索,但没有找到合适的解决方案。我是结构体,请帮忙!

我检查的长度如下:

if ( $('#LoginEmail').val().length > 0){
    $(this).siblings('.placeholder').addClass('active');
    } else{
      $(this).siblings('.placeholder').removeClass('active');
    }

// Material Input
$('.form-control input').blur();
$('.placeholder').click(function() {
  $(this).siblings('input').focus();
});
$('.form-control').focus(function() {
  $(this).siblings('.placeholder').removeClass('active').addClass('active');
});   

// on blur
$('.form-control input').blur(function() {
  if ( $(this).val().length > 0){
    $(this).siblings('.placeholder').addClass('active');
    } else{
      $(this).siblings('.placeholder').removeClass('active');
    }
});

// Length Check
if ( $('#LoginEmail').val().length > 0){
    $(this).siblings('.placeholder').addClass('active');
    } else{
      $(this).siblings('.placeholder').removeClass('active');
    }
.inputField input, .inputField select {
    width: 100%;
    height: 35px;
    padding: 10px 23px;
    border: 1px solid #c5c5c5;
    font-size: 15px;
    -webkit-box-shadow: none;
    box-shadow: none;
    border-radius: 0;
    -webkit-border-radius: 0;
    background: #fff!important;
}
.inputField {
    margin: 10px 0 0;
}
.inputField input, .inputField select {
    width: 100%;
    height: 55px;
    padding: 10px 23px;
    border: 1px solid #c5c5c5;
    font-size: 15px;
    -webkit-box-shadow: none;
    box-shadow: none;
    border-radius: 0;
    -webkit-border-radius: 0;
    background: #fff !important;
}
.inputField textarea {
    width: 100%;
    height: 120px;
    padding: 10px 23px;
    border: 1px solid #c5c5c5;
    font-size: 15px;
    -webkit-box-shadow: none;
    box-shadow: none;
    border-radius: 0;
    -webkit-border-radius: 0;
    background: #fff !important;
}
.inputField select .star {
    color: #f00;
}
.inputField.half {
    width: 49.5%;
    float: left;
    margin: 10px 1% 0px 0;
}
.inputField.half: nth-of-type(even) {
    margin-right: 0;
    float: left;
}
.inputField {
    width: 100%;
    position: relative;
    height: auto;
    display: inline-block;
    padding: initial;
    border: 0;
    box-shadow: none;
}
.placeholder {
    position: absolute;
    top: 17px;
    left: 23px;
    transition: all 0.3s ease;
}
.inputField.form-control select {
    color: #777;
}
.inputField select {
    color: #777;
}
.inputField .placeholder.active {
    top: -11px;
    background: #fff;
    padding: 0 2px;
}
.inputField .placeholder {
    position: absolute;
    top: 30px;
    left: 23px;
    -webkit-transition: all 0.3s ease;
    -o-transition: all 0.3s ease;
    transition: all 0.3s ease;
}
<div class="inputField form-control">          
 <input type="email" class="form-control" id="LoginEmail" required> 
 <div class="placeholder">
   <label for="email">Email ID</label>
   <span class="star">*</span>
</div>         
</div>
<div class="inputField form-control">         
 <input type="Password" class="form-control" id="LoginPassword" required>  
 <div class="placeholder">
   <label for="Password">Password </label>
   <span class="star">*</span>
</div>
</div>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>

最佳答案

终于得到答案了:

$(window).bind("load", function() { 
$.each($('.inputField.form-control input:-webkit-autofill'), function() {
    var autofilled = $(this);
        var inputblock = $(this).next()
    $(inputblock).addClass('active');

});
}); 

关于javascript - 当我自动完成输入字段时,值被标签覆盖并且在加载时也没有获得长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54631539/

相关文章:

jquery - Wordpress jquery 选择一个子菜单项?

javascript - 触发点击以id结尾的按钮以数字结尾

html - 如何在 Firefox 上使用 css 使伪元素可见和可点击

javascript - 在 Polymer 中铁形式的 ajax 响应后更新 UI

javascript - 区分 iPad 和 .来自网络应用程序内部的 iPhone?

javascript - Bootstrap 完成一个函数后,如何在 jQuery 中运行一个函数?

javascript - 复选框点击后不想勾选或取消勾选

javascript - jQuery 悬停函数

html - 为移动 View 正确设置 CSS 样式?

jquery - 如何在 jquery 移动网页周围创建边框?