admin管理员组文章数量:1425697
How can I display the "Password entered by the user" on the tooltip placed on the input element type=password
, only if the "Show Password" checkbox is selected. ?
what I am trying to achive is.
if user checks the checkbox "Show Password" then the password should be visible in the plaintext using the tooltip.
so far I have done like this.
HTML
<form>
<span class="form-label">Password</span>
<input type="password" id="password" class="form-control" style="width:350px;" placeholder="Password" data-toggle="tooltip" data-placement="right" title="" required>
<div class="checkbox">
<label><input type="checkbox" id="show-password" onClick="javascript:showPassword(this)">Show Password</label>
</div>
</form>
JAVASCRIPT
function showPassword(obj) {
if (obj.checked) {
/* checkmark is checked*/
/*show tooltip*/
$('#password').tooltip('show');
/*create onkeyup event so the tooltip changes as the password changes.*/
$("#password").keyup(function () {
var entered_password = document.getElementById("password").value;
$("#password").attr("title", entered_password);
$("#password").tooltip('fixTitle');
});
} else {
//hide the tooltip//
}
}
CSS
@import url(".2.0/cerulean/bootstrap.min.css");
@import url(".2.0/css/bootstrap-theme.min.css");
/
so far its only working if I select and reselect the checkbox but not as I type the password.
How can I display the "Password entered by the user" on the tooltip placed on the input element type=password
, only if the "Show Password" checkbox is selected. ?
what I am trying to achive is.
if user checks the checkbox "Show Password" then the password should be visible in the plaintext using the tooltip.
so far I have done like this.
HTML
<form>
<span class="form-label">Password</span>
<input type="password" id="password" class="form-control" style="width:350px;" placeholder="Password" data-toggle="tooltip" data-placement="right" title="" required>
<div class="checkbox">
<label><input type="checkbox" id="show-password" onClick="javascript:showPassword(this)">Show Password</label>
</div>
</form>
JAVASCRIPT
function showPassword(obj) {
if (obj.checked) {
/* checkmark is checked*/
/*show tooltip*/
$('#password').tooltip('show');
/*create onkeyup event so the tooltip changes as the password changes.*/
$("#password").keyup(function () {
var entered_password = document.getElementById("password").value;
$("#password").attr("title", entered_password);
$("#password").tooltip('fixTitle');
});
} else {
//hide the tooltip//
}
}
CSS
@import url("http://maxcdn.bootstrapcdn./bootswatch/3.2.0/cerulean/bootstrap.min.css");
@import url("http://maxcdn.bootstrapcdn./bootstrap/3.2.0/css/bootstrap-theme.min.css");
http://jsfiddle/834Nj/1/
so far its only working if I select and reselect the checkbox but not as I type the password.
Share Improve this question edited Aug 6, 2014 at 8:18 urbz 2,6671 gold badge21 silver badges29 bronze badges asked Aug 6, 2014 at 8:07 user1642018user1642018 14-
1
You don't need to listen
keyup
event in your case. Listenchange
event instead – hindmost Commented Aug 6, 2014 at 8:12 - It should not possible. It poses security risk. – twicejr Commented Aug 6, 2014 at 8:20
- It doesn't pose a security risk. In newer versions of IE there is a little button that allows you to reveal your typed password. On most WiFi login screens there is a check box to show the password in plain text. It shouldn't be enabled by default, but if the user wants to reveal their own password thats their choice. – Rob Quincey Commented Aug 6, 2014 at 8:25
- 2 I would do it like this: jsfiddle/834Nj/4, simply changing the input type. – Ilya Luzyanin Commented Aug 6, 2014 at 8:45
- 1 @AMB, well I did similar thing for my projects. It looks crappy in IE11, cause it has its own "eye" icon, which shows password no matter what your checkbox value is. So maybe you should consider that. – Ilya Luzyanin Commented Aug 6, 2014 at 8:51
1 Answer
Reset to default 5You can do It like this :
$("#show-password").on('change' , function(){
if($(this).is(':checked')){
$('#password').tooltip({title : $('#password').val(), placement:'right',trigger:'manual'});
$('#password').tooltip('show');
}
else{
$('#password').tooltip('destroy');
}
})
$('#password').on('keyup' , function(){
if($('#show-password').is(':checked')){
$(this).data('bs.tooltip').options.title = $(this).val();
$(this).data('bs.tooltip').options.animation = false;
$(this).tooltip('fixTitle').tooltip('show');
if($(this).val()==""){
$(this).tooltip('hide');
}
}
});
http://jsfiddle/834Nj/7/
版权声明:本文标题:javascript - How can I show entered password using tooltip on input type=password in bootstrap? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745412936a2657549.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论