[英]How we show password while login in webforms using asp.net
I have login form 我有登录表格
I want to show password when check box is checked. 我想在选中复选框时显示密码。 I write below code
我写下面的代码
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<asp:TextBox runat="server" ID="txtPassword" Width="100%" TextMode="Password"></asp:TextBox>
</asp:TableCell>
<asp:TableCell runat="server">
<asp:CheckBoxList runat="server" ID="showHidePassword">
<asp:ListItem Value="1" Text="Show Password"></asp:ListItem>
</asp:CheckBoxList>
</asp:TableCell>
</asp:TableRow>
And try some JQuery code 并尝试一些JQuery代码
$(function(){
$("#showHidePassword").bind("click",function(){
if($(this).is(":checked")){
// then I try to remove the "TextMode=Password"
// and think may be it works but there is no method that change textmode
}
});
});
Please help. 请帮忙。
You can try changing the type
attribute on change event, you can do something like this as an example: 您可以尝试在change事件上更改
type
属性,可以执行以下示例:
$(function() { $("#showHidePassword").on("change", function() { var checked = this.checked; $(this).siblings('input').attr('type', function() { return checked ? "text" : "password"; }) }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="checkbox" id="showHidePassword">show password <br> <input type="password">
Actually I use CheckBoxList
and use the ID of this control. 实际上,我使用
CheckBoxList
并使用此控件的ID。 But need control of checked item. 但是需要检查项目的控制。 So first of all use
CheckBox
instead of CheckBoxList
. 因此,首先使用
CheckBox
而不是CheckBoxList
。
And write below code in head section. 并在下面的部分中编写以下代码。
$(function () {
$("#showHidePassword").bind("click", function () {
var txtPassword = $("#txtPassword");
if ($(this).is(":checked")) {
txtPassword.after('<input onchange = "PasswordChanged(this);" id = "txt_' + txtPassword.attr("id") + '" type = "text" value = "' + txtPassword.val() + '" />');
txtPassword.hide();
} else {
txtPassword.val(txtPassword.next().val());
txtPassword.next().remove();
txtPassword.show();
}
});
});
function PasswordChanged(txt) {
$(txt).prev().val($(txt).val());
}
That's it. 而已。
You can try this 你可以试试这个
HTML 的HTML
<input class="pwd" type="password">
<input class="chk" type="checkbox">Show Password
JQUERY JQUERY
$(document).ready(function() {
$('.chk').on('click', function() {
if ($('.chk').prop("checked")) {
$('.pwd').prop('type', 'text');
} else {
$('.pwd').prop('type', 'password');
}
});
});
kindly check https://jsfiddle.net/vzuLn88j/ 请检查https://jsfiddle.net/vzuLn88j/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.