我在我的网页上使用了bootstrap material kit,但是我的问题是标签没有在chrome上自动填充。我已经四处搜索,看到这是一个已知问题,并尝试使用建议的解决方案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>
答案 0 :(得分:3)
这最终对我有用:
$(window).load($.debounce(200,function(){
$('input:-webkit-autofill').each(function(){
if ($(this).val().length !== "") {
$(this).siblings('label, i').addClass('active');
}
});
}));
答案 1 :(得分:0)
我已经浏览了您为bootstrap material kit提到的链接,我创建了此示例代码,其中包含了相同的JS和css文件,这些文件已添加到creative-tim的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>
&#13;
答案 2 :(得分:0)
如果您不想自动填充,请将自动填充属性赋予输入元素。 (注意:autocomplete =&#34; off&#34;不起作用)
//Custom Authorize class that derives from the existing AuthorizeAttribute
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
private string[] _allowedRoles;
public CustomAuthorizeAttribute(params string[] roles)
{
//allowed roles
_allowedRoles = roles;
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
var roleManager = httpContext.GetOwinContext().Get<ApplicationUserManager>();
//Grab all of the Roles for the current user
var roles = roleManager.GetRoles(httpContext.User.Identity.GetUserId());
//Determine if they are currently in any of the required roles (and allow / disallow accordingly)
return _allowedRoles.Any(x => roles.Contains(x));
}
}