【问题标题】:Password input field in Safari and ChromeSafari 和 Chrome 中的密码输入字段
【发布时间】:2014-06-10 21:14:13
【问题描述】:

我现在在 IE 中完成了我的应用程序,一切正常,然后我在 Safari 和 Chrome 中运行我的应用程序,遇到了一个问题,当我有一个类型为 PasswordInput field 时,要显示的图标密码和通知用户大写锁定的消息框不存在。

现在我知道不同的浏览器支持不同的东西,我只是想知道有没有人找到任何我可以使用或添加到我的代码中以使其工作的东西?

这就是我的意思(IE):

现在是 Safari:

<%-- Password Input --%>
<input runat="server" id="txt_password" class="InputBoxLoginPage" type="password" placeholder="Password..." />

【问题讨论】:

标签: javascript html css google-chrome safari


【解决方案1】:

我明白你的意思。我也有这个问题。不同的浏览器以不同的方式呈现密码字段。所以我使用了这个解决方法:

<div class="well_head" style="height: 36px;">  
    <input type="text" class="password" style="border: 0px; float: right; padding-left: 30px;" />  
    <input type="password" class="password" style="border: 0px; float: right; padding-left: 30px;" />  
    <i class="icon-password" style="float: left; margin-top: 4px;"></i>  
</div>
<div id="capsWarning" style="display:none;">Caps Lock is on.</div>  

这里是@misterManSam 用于大写锁定弹出窗口的代码。

$(document).ready(function() {  

    /*   
    * Bind to capslockstate events and update display based on state   
    */  
    $(window).bind("capsOn", function(event) {  
        if ($("#Passwd:focus").length > 0) {  
            $("#capsWarning").show();  
        }  
    });  
    $(window).bind("capsOff capsUnknown", function(event) {  
        $("#capsWarning").hide();  
    });  
    $("#Passwd").bind("focusout", function(event) {  
        $("#capsWarning").hide();  
    });  
    $("#Passwd").bind("focusin", function(event) {  
        if ($(window).capslockstate("state") === true) {  
            $("#capsWarning").show();  
        }  
    });  

    /*   
    * Initialize the capslockstate plugin.  
    * Monitoring is happening at the window level.  
    */  
    $(window).capslockstate();  

});

我正在使用 AngularJS,单击该图标我将切换两个字段。 两个字段(文本和密码)也绑定到同一个变量。

这对我有用。希望对你也有帮助。

PS。为 CapsLock 弹出 div 做你的风格 :)
一切顺利。

【讨论】:

    【解决方案2】:

    好的,因此大写锁定警告是基于 IE 的。不知道:)

    一个好的解决方案是使用 jQuery 和 HTML/CSS 来模拟它。

    This is a fiddle I found。开始在密码字段中输入大写锁定以接收警告。

    This is the github page for the jQuery plugin.

    这是它的简单实现。

    HTML

    <div id="form">
      username
      <input type="text" />
      <br>
      password
      <input type="password" name="Passwd" id="Passwd" />
      <div id="capsWarning" style="display:none;">Caps Lock is on.</div>
    </div>
    

    jQuery

    $(document).ready(function() {
    
        /* 
        * Bind to capslockstate events and update display based on state 
        */
        $(window).bind("capsOn", function(event) {
            if ($("#Passwd:focus").length > 0) {
                $("#capsWarning").show();
            }
        });
        $(window).bind("capsOff capsUnknown", function(event) {
            $("#capsWarning").hide();
        });
        $("#Passwd").bind("focusout", function(event) {
            $("#capsWarning").hide();
        });
        $("#Passwd").bind("focusin", function(event) {
            if ($(window).capslockstate("state") === true) {
                $("#capsWarning").show();
            }
        });
    
        /* 
        * Initialize the capslockstate plugin.
        * Monitoring is happening at the window level.
        */
        $(window).capslockstate();
    
    });
    

    对于 CSS,您可以定位 #capsWarning 并使其看起来像您想要的那样。

    【讨论】:

    • 不错。还想提醒你..“显示密码的图标不存在。”因此,将您的代码添加到我的代码中可以完成此答案。 :) 谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-12
    • 2011-10-14
    • 1970-01-01
    • 2019-07-14
    • 1970-01-01
    相关资源
    最近更新 更多