【问题标题】:How do I get the ASP.Net MVC Password HTML Helper to show characters as I type?如何让 ASP.Net MVC Password HTML Helper 在我键入时显示字符?
【发布时间】:2014-12-12 15:49:22
【问题描述】:

我在 MVC5 中使用 Password HTML Helper 来隐藏输入的社会安全号码。

@Html.Password("s", null, new { @maxlength = 9, autocomplete = "off" })

我看到的问题是您在键入时只看到点。有什么方法可以修改助手行为以显示您正在输入的字符一两秒钟然后将它们转换为点?这种行为会让用户确认他们正在输入正确的字符。如果无法修改辅助行为,是否有其他方法可以完成此操作?

【问题讨论】:

标签: asp.net-mvc


【解决方案1】:

我找到了这个小提琴,也许你可以把它用作一个选项

http://jsfiddle.net/Ngtp7/

$(function(){
    $(".showpassword").each(function(index,input) {
        var $input = $(input);
        $('<label class="showpasswordlabel"/>').append(
            $("<input type='checkbox' class='showpasswordcheckbox' />").click(function() {
                var change = $(this).is(":checked") ? "text" : "password";
                var rep = $("<input type='" + change + "' />")
                    .attr("id", $input.attr("id"))
                    .attr("name", $input.attr("name"))
                    .attr('class', $input.attr('class'))
                    .val($input.val())
                    .insertBefore($input);
                $input.remove();
                $input = rep;
             })
        ).append($("<span/>").text("Show password")).insertAfter($input);
    });
});

【讨论】:

  • 不错的选择,但不是问题的答案。
猜你喜欢
  • 2013-04-05
  • 1970-01-01
  • 2010-10-29
  • 2014-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-27
相关资源
最近更新 更多