7

我在我的页面上使用引导材料工具包,但我遇到了一个问题,即在 chrome 中自动填充时标签没有出现。我四处搜索,发现这是一个已知问题,并尝试使用此处建议的解决方案。但它仍然不适合我。不知道怎么解决?

这就是我如何称呼我的样式表:

<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>
4

3 回答 3

4

这最终对我有用:

$(window).load($.debounce(200,function(){
    $('input:-webkit-autofill').each(function(){
        if ($(this).val().length !== "") {
            $(this).siblings('label, i').addClass('active');
        }
    });
}));
于 2017-02-17T10:01:10.550 回答
0

我已经浏览了您提到的引导材料工具包的链接,并且我通过包含添加到creative-tim 的引导材料工具包网站上的相同 JS 和 css 文件来创建此示例代码。我相信您的要求是一旦输入成为焦点,就拉起密码标签。

下面是我的代码,它做同样的事情。我希望它对你有帮助。

<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>

于 2017-02-13T19:35:32.633 回答
0

如果您不想自动填充,则将 autocomplete 属性赋予输入元素。(注意:autocomplete="off" 不起作用)

<form id="testForm">
    <input type="text"autocomplete="email">
    <input type="password" autocomplete="new-password">
</form>
于 2018-06-01T06:02:40.957 回答