我試圖在特定時間使用眼睛圖標顯示密碼。我嘗試添加類併爲該輸入添加背景圖像。但高度和寬度比文本框大。當試圖更改高度時,輸入大小隨背景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比輸入文本更大。 –