Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Mousedown事件抑制focusout事件?_Javascript_Html - Fatal编程技术网

Javascript Mousedown事件抑制focusout事件?

Javascript Mousedown事件抑制focusout事件?,javascript,html,Javascript,Html,我有一个应用程序,其中有一个密码字段。当用户将鼠标放在眼睛图标上时,我们希望将密码显示为文本。但是,在某些情况下,不会调用focus out事件。这就是代码的样子。mousedown事件是否抑制焦点输出事件。转换为文本和密码可以正常工作,但该值不会绑定到模型 $(document).on('mousedown mouseup', '.passfield', function (event) { togglepasswordreset(event); }); window.togglep

我有一个应用程序,其中有一个密码字段。当用户将鼠标放在眼睛图标上时,我们希望将密码显示为文本。但是,在某些情况下,不会调用focus out事件。这就是代码的样子。mousedown事件是否抑制焦点输出事件。转换为文本和密码可以正常工作,但该值不会绑定到模型

$(document).on('mousedown mouseup', '.passfield', function (event) {
    togglepasswordreset(event);
});

window.togglepasswordreset = function (event) {
    var element = event.currentTarget;
    if (element) {
        if (event.type == 'mousedown') {
            $(element).parent().children('input').attr('type', 'text');
        }
        else {
            $(element).parent().children('input').attr('type', 'password');
        }
    }
};
这就是html的外观

<div class="field">
    <span class="controls passfield" for="showpass"><b class="icon_eye"></b></span>
     @*<input type="checkbox" value="Show password" class="passcheckbox" id="showpass" tabindex="-1" data-bind="click:onShowPass">*@
     <label for="inputEmail" class="floatLblDn">@Resources.Password</label>
     <input type="password" class="floatTxt myStyle" id="inputPassword" name="inputPassword" data-bind="value: Password">
</div>

@**@
@资源。密码

如果要在鼠标悬停在某个元素上时显示密码,而在该元素离开时隐藏密码,可以使用mouseover和mouseout事件

如果要在鼠标悬停在某个元素上时显示密码,而在该元素离开时隐藏密码,可以使用mouseover和mouseout事件

如果要在鼠标悬停在某个元素上时显示密码,而在该元素离开时隐藏密码,可以使用mouseover和mouseout事件

如果要在鼠标悬停在某个元素上时显示密码,而在该元素离开时隐藏密码,可以使用mouseover和mouseout事件

我为你写了一个有用的例子

HTML

<div>
        <input type="password" class="passfield" id="passf" />
        <label style="margin-left: -30px; background: #ffde00; cursor: pointer;"        for="#passf">See</label>
</div>

看见
脚本

<script>
    $(function() {
        $('label').click(function(event) {
        });
        $('label').mousedown(function(event) {
            $('.passfield').attr('type', 'text');
        });
        $('label').mouseup(function(event) {
            $('.passfield').attr('type', 'password');
            $('.passfield').focus();
        }); 
    });
</script>

$(函数(){
$(“标签”)。单击(函数(事件){
});
$('label').mousedown(函数(事件){
$('.passfield').attr('type','text');
});
$('label').mouseup(函数(事件){
$('.passfield').attr('type','password');
$('.passfield').focus();
}); 
});

我为您编写了一个帮助示例

HTML

<div>
        <input type="password" class="passfield" id="passf" />
        <label style="margin-left: -30px; background: #ffde00; cursor: pointer;"        for="#passf">See</label>
</div>

看见
脚本

<script>
    $(function() {
        $('label').click(function(event) {
        });
        $('label').mousedown(function(event) {
            $('.passfield').attr('type', 'text');
        });
        $('label').mouseup(function(event) {
            $('.passfield').attr('type', 'password');
            $('.passfield').focus();
        }); 
    });
</script>

$(函数(){
$(“标签”)。单击(函数(事件){
});
$('label').mousedown(函数(事件){
$('.passfield').attr('type','text');
});
$('label').mouseup(函数(事件){
$('.passfield').attr('type','password');
$('.passfield').focus();
}); 
});

我为您编写了一个帮助示例

HTML

<div>
        <input type="password" class="passfield" id="passf" />
        <label style="margin-left: -30px; background: #ffde00; cursor: pointer;"        for="#passf">See</label>
</div>

看见
脚本

<script>
    $(function() {
        $('label').click(function(event) {
        });
        $('label').mousedown(function(event) {
            $('.passfield').attr('type', 'text');
        });
        $('label').mouseup(function(event) {
            $('.passfield').attr('type', 'password');
            $('.passfield').focus();
        }); 
    });
</script>

$(函数(){
$(“标签”)。单击(函数(事件){
});
$('label').mousedown(函数(事件){
$('.passfield').attr('type','text');
});
$('label').mouseup(函数(事件){
$('.passfield').attr('type','password');
$('.passfield').focus();
}); 
});

我为您编写了一个帮助示例

HTML

<div>
        <input type="password" class="passfield" id="passf" />
        <label style="margin-left: -30px; background: #ffde00; cursor: pointer;"        for="#passf">See</label>
</div>

看见
脚本

<script>
    $(function() {
        $('label').click(function(event) {
        });
        $('label').mousedown(function(event) {
            $('.passfield').attr('type', 'text');
        });
        $('label').mouseup(function(event) {
            $('.passfield').attr('type', 'password');
            $('.passfield').focus();
        }); 
    });
</script>

$(函数(){
$(“标签”)。单击(函数(事件){
});
$('label').mousedown(函数(事件){
$('.passfield').attr('type','text');
});
$('label').mouseup(函数(事件){
$('.passfield').attr('type','password');
$('.passfield').focus();
}); 
});

您可以只使用mouseover和mouseout事件

我创建了一个JSFIDLE来向您展示

只需输入密码并将鼠标悬停在文本“显示密码”上

html


您可以使用mouseover和mouseout事件

我创建了一个JSFIDLE来向您展示

只需输入密码并将鼠标悬停在文本“显示密码”上

html


您可以使用mouseover和mouseout事件

我创建了一个JSFIDLE来向您展示

只需输入密码并将鼠标悬停在文本“显示密码”上

html


您可以使用mouseover和mouseout事件

我创建了一个JSFIDLE来向您展示

只需输入密码并将鼠标悬停在文本“显示密码”上

html

如果用户拖到另一个元素上,则可能不会在
.passfield
上点火

如果用户在元素外部单击,则拖动到元素上并释放 按钮,这仍然被视为鼠标悬停事件。这一系列的 在大多数用户界面中,操作不被视为按钮按下,因此 通常最好使用click事件,除非我们知道 mouseup事件适用于特定情况

类似地,事件可能无法按预期工作

如果用户单击某个元素,将其拖离,然后释放 按钮,这仍然被视为鼠标下降事件。这一系列的 在大多数用户中,操作被视为按钮按下的“取消” 接口,因此通常最好使用click事件,除非 知道mousedown事件更适合于特定的 情况

在这里,我将mousedown绑定到
.passfield
,但在整个文档上有mouseup。改变功能,而不是切换鼠标。如果用户拖动到另一个元素上,鼠标总是恢复为密码,鼠标向下设置为文本。

可能不会在
.passfield
上触发

如果用户在元素外部单击,则拖动到元素上并释放 按钮,这仍然被视为鼠标悬停事件。这一系列的 在大多数用户界面中,操作不被视为按钮按下,因此 通常最好使用click事件,除非我们知道 mouseup事件适用于特定情况

类似地,事件可能无法按预期工作

如果用户单击某个元素,将其拖离,然后释放 按钮,这仍然被视为鼠标下降事件。这一系列的 在大多数用户中,操作被视为按钮按下的“取消” 接口,因此通常最好使用click事件,除非 知道mousedown事件更适合于特定的 情况

在这里,我将mousedown绑定到
.passfield
,但在整个文档上有mouseup。更改功能,使鼠标始终恢复为密码,而不是切换鼠标。鼠标向下设置为文本。

可能不会在