admin管理员组文章数量:1305403
@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 bees visible. I know this will be through jquery or Javascript, but I am not able to understand that in mvc. How to apply that technique in 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?
@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 bees visible. I know this will be through jquery or Javascript, but I am not able to understand that in mvc. How to apply that technique in 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?
Share Improve this question edited Dec 28, 2017 at 12:14 Zabavsky 13.6k8 gold badges57 silver badges80 bronze badges asked Dec 28, 2017 at 12:06 user8256152user8256152 1- 2 The only different between Password and TextBox is the html type attribute. Use jquery or javascript to locate the element id, and change its type to text. – Orel Eraki Commented Dec 28, 2017 at 12:12
4 Answers
Reset to default 5change 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./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")
just replace the #Password with your selector and if you want to change it back just do:
$("#Password").attr("type","password")
Add the javascript in your page to achieve it. 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
<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
function ShowHidePass(objChk)
{
if(objChk.checked)
passwordField.type="text"
else
passwordField.type="password"
}
本文标签: javascripthow to show the password hidden field in mvc using Html helperStack Overflow
版权声明:本文标题:javascript - how to show the password hidden field in mvc using Html helper - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741804377a2398411.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论