[英]password show/hide fontawesome icon problem and not placed into input field
[英]How to icon in password field to show & hide password in rails
我的代碼:
div.form-group.col-md-12
label =t('.password')
= f.text_field :password,
required: true,
label: false,
type: 'password',
placeholder: 'Password',
input_html: {autocomplete: "new-password"},
class: 'form-control input-sm form-control-sm'
此表單字段用於輸入密碼。 我想要在輸入字段框的右側有一個眼睛按鈕,它可以切換密碼顯示和隱藏。 我知道它可以由JS完成。 但我不知道該怎么做。
$("body").on('click', '.toggle-password', function() { $(this).toggleClass("fa-eye fa-eye-slash"); var input = $("#pass_log_id"); if (input.attr("type") === "password") { input.attr("type", "text"); } else { input.attr("type", "password"); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <span toggle="#password-field" class="fa fa-fw fa-eye field_icon toggle-password">Show/Hide</span> <input type="password" id="pass_log_id"/>
=>代表html你可以使用這個代碼
%script{:src => "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"}
%span.fa.fa-fw.fa-eye.field_icon.toggle-password{:toggle => "#password-field"} Show/Hide
%input#pass_log_id{:type => "password"}/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.