Bootstrap material 浮动标签无法自动填充

Bootstrap material floating label not working on autofill

我正在使用 bootstrap material kit on my page, but I have a problem with a label not going up on autofill in chrome. I have searched around and saw that is a known issue, and have tried with using the solution suggested here。但它仍然不适合我。不知道如何解决?

我是这样称呼我的样式表的:

<link href="/css/material-kit/css/bootstrap.min.css" rel="stylesheet" />
<link href="/css/material-kit/css/material-kit.css" rel="stylesheet"/>
<link href="/css/landing-page.css" rel="stylesheet"/>

Html:

<div class="form-group label-floating">
    <label class="control-label">Password</label>
    <input type="password" name="password" class="form-control" required/>
    @if ($errors->has('password'))
        <span class="help-block">
            <strong>{{ $errors->first('password') }}</strong>
        </span>
    @endif
</div>

和脚本:

<!--   Core JS Files   -->
<script src="/js/landing-page/jquery.min.js" type="text/javascript"></script>
<script src="/js/landing-page/bootstrap.min.js" type="text/javascript"></script>
<script src="/js/landing-page/material.min.js"></script>
<script>
    $(document).ready(function() {
            $.material.options.autofill = true;
            $.material.init();
    });
</script>

我已经完成了您为 bootstrap material kit 提到的 link,并且我通过包含添加到 [=22] 的相同 JS 和 css 文件创建了这个示例代码=] 的 bootstrap material-kit 网站。我相信您的要求是在输入焦点集中后拉出密码标签。

下面是我执行相同操作的代码。我希望它能帮助你。

<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Bootstrap Material</title>

  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:300,400,500,700" type="text/css">

  <!-- Bootstrap -->
  <link href="http://demos.creative-tim.com/material-kit/assets/css/bootstrap.min.css" rel="stylesheet">

  <!-- Bootstrap Material Design -->
  <link href="http://demos.creative-tim.com/material-kit/assets/css/material-kit.css" rel="stylesheet">


</head>

<body>
  <div class="card">
    <form class="form" method="" action="">
      <div class="content">
        <div class="input-group">
          <span class="input-group-addon">
    <i class="material-icons">face</i>
     </span>
          <input type="text" class="form-control" placeholder="First Name...">
        </div>
        <div class="input-group">
          <span class="input-group-addon">
   <i class="material-icons">email</i>
    </span>
          <input type="text" class="form-control" placeholder="Email...">
        </div>
        <div class="input-group">
          <span class="input-group-addon">
   <i class="material-icons">lock_outline</i>
    </span>
            <div class="form-group label-floating">
  <label class="control-label">Password</label>
  <input type="password" name="password" class="form-control" required value="37648763"/>

</div>
            <div class="form-group label-floating">
  <label class="control-label">Password</label>
  <input type="password" name="password" class="form-control" required/>

</div>
          
        </div>
      </div>
      <div class="footer text-center">
        <a href="#pablo" class="btn btn-simple btn-primary btn-lg">Get Started</a>
      </div>
    </form>
  </div>
  <script src="http://demos.creative-tim.com/material-kit/assets/js/jquery.min.js"></script>
  <script src="http://demos.creative-tim.com/material-kit/assets/js/material.min.js"></script>
  <script src="http://demos.creative-tim.com/material-kit/assets/js/material-kit.js"></script>
</body>

</html>

这最终对我有用:

$(window).load($.debounce(200,function(){
    $('input:-webkit-autofill').each(function(){
        if ($(this).val().length !== "") {
            $(this).siblings('label, i').addClass('active');
        }
    });
}));

如果您不想自动填充,请为输入元素提供自动完成属性。 (注意:autocomplete="off" 将不起作用)

<form id="testForm">
    <input type="text"autocomplete="email">
    <input type="password" autocomplete="new-password">
</form>