2017-07-03 24 views
-3

特定の時間、目のアイコンを使用してパスワードを表示しようとしています。私はクラスを追加しようとしましたが、その入力の背景画像を追加しようとしました。しかし、高さと幅がテキストボックスより大きくなりました。高さを変えようとすると、背景が入力の中にあるので入力サイズが小さくなりました。入力タイプのテキスト内に画像を追加する

これを解決する方法はありますか?

$("#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、それが働いsの罰金を試してみました。

+0

http://www.jqueryscript.net/form/Toggle-Password-Visibility-With-jQuery-hideShowPassword.html – aghilpro

+0

@aghilpro、私は任意のjQueryのプラグインを使用せずにこれを達成しようとしています:)私は」パスワードの表示/非表示が可能です。問題はimgが入力テキストよりも大きいことです。 –

答えて

1

のサイズを変更するには、CSSで使用background-size: 10px 10px;あなたは高さと幅のためのバックグラウンド・サイズを使用することができ、私の編集をチェック

$("#ShowCurrentPassword").click(function(){ 
 
$('#Password').attr('type', 'text'); 
 
setTimeout(function(){$('#Password').attr('type', 'password'); }, 900); 
 
});
input{ 
 
background: url(https://d30y9cdsu7xlg0.cloudfront.net/png/7467-200.png) no-repeat; 
 
background-size: 25px; 
 
background-position: 2%; 
 
}
<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>

+0

ありがとう、その作業:)しかし、目のアイコンがそこにあるべきではないパスワードを入力する! –

+0

@HemaNandagopalどうやって動いているの?あなたは目のアイコンをクリックすることができますか?私は –

+0

ではないので、クラスを使用しました。jqueryプラグインをインポートしましたか? –

関連する問題