[英]how to show the password hidden field in mvc using Html helper
@Html.Password("pasword", null, new { @class = "form-control frmField", placeholder = "Password" })
I am using this and I want that here should be one button which I click and the the password becomes visible. 我正在使用它,我希望这里应该是一个单击的按钮,并且密码可见。 I know this will be through jquery or Javascript, but I am not able to understand that in mvc. 我知道这将通过jquery或Javascript,但是我无法在mvc中理解。 How to apply that technique in mvc? 如何在MVC中应用该技术?
<input data-toggle="password" type="password" data-placement="after" data-eye-class="glyphicon" data-eye-open-class="glyphicon glyphicon-eye-open" data-eye-close-class="glyphicon glyphicon-eye-close" data-eye-class-position="true" class="form-control pwd">
<input type="text" class="form-control" placeholder="password" style="display:none;" />
I have used this and it worked good. 我已经用过了,效果很好。 How to implement this in mvc? 如何在mvc中实现呢?
change Password type to text type 将密码类型更改为文本类型
$( ".btnShow" ).mousedown(function() { $(".pwd").attr("type","text"); }); $( ".btnShow" ).on("mouseleave",function() { $(".pwd").attr("type","password"); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="password" class="form-control pwd"> <input type="button" class="btnShow" value="show"/>
$("#Password").attr("type","text")
只需将#Password替换为您的选择器,然后将其更改回即可:
$("#Password").attr("type","password")
Add the javascript in your page to achieve it. 在页面中添加javascript以实现它。 Here is a sample for your reference. 这是一个示例供您参考。
@Html.Password("pasword", null, new { @class = "form-control frmField", placeholder = "Password" })
<input type="button" id="showHidePassword" value="Show" />
<script>
$("#showHidePassword").click(function(){
if($(this).val() == "Show"){
$(this).val("Hide");
$("#password").attr("type", "text");
} else {
$(this).val("Show");
$("#password").attr("type", "password");
}
});
</script>
Assign a Id to the password field using the below line 使用下面的代码行向密码字段分配一个ID
<input id="passwordField" data-toggle="password" type="password" data-placement="after" data-eye-class="glyphicon" data-eye-open-class="glyphicon glyphicon-eye-open" data-eye-close-class="glyphicon glyphicon-eye-close" data-eye-class-position="true" class="form-control pwd">
<input type="checkbox" onclick="ShowHidePass(this)" />
Add the following JS function to script block 将以下JS函数添加到脚本块
function ShowHidePass(objChk)
{
if(objChk.checked)
passwordField.type="text"
else
passwordField.type="password"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.