我试图在特定时间使用眼睛图标显示密码。我尝试添加类并为该输入添加背景图像。但高度和宽度比文本框大。当试图更改高度时,输入大小随背景img在输入内部而减小。在输入文字内添加图像
有什么办法可以解决这个问题吗?
$("#ShowCurrentPassword").click(function(){
$('#Password').attr('type', 'text');
setTimeout(function(){$('#Password').attr('type', 'password'); }, 900);
});
input{
background: url("eye.png") no-repeat fixed;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="form-group">
<label for="" class="col-sm-4 control-label">Current Password</label>
<div class="col-sm-7"><input type="password" class="form-control" id="Password" placeholder=""></div>
<div class="col-sm-1"> <i class="glyphicon glyphicon-eye-open" id="ShowCurrentPassword"></i></div>
</div>
P.S:我试着用自举glyphicon glyphicon眼开 “ID =” ShowCurrentPassword和它那工作的罚款。
http://www.jqueryscript.net/form/Toggle-Password-Visibility-With-jQuery-hideShowPassword.html – aghilpro
@aghilpro,我试图实现这一点,而不使用任何jQuery插件:)我'能够显示/隐藏密码。问题在于img比输入文本更大。 –