简体   繁体   English

jQuery .focusout()也是在Firefox 33.1中出现.keyup()的时候

[英]jQuery .focusout() also when .keyup() occurs in Firefox 33.1

when I release a key in an input form html field, I get in Firefox 33.1 in jQuery an keyup event and also an unwanted focusout event. 当我在输入表单html字段中释放一个键时,我在jQuery中的Firefox 33.1中获得了一个keyup事件以及一个不需要的focusout事件。 I just want the keyup event when releasing the key. 我只是想在释放密钥时获得keyup事件。

This is my code: 这是我的代码:

<html>
    <head>
        <script src="libraries/jquery/jquery-1.11.1.min.js"></script>
    </head>
    <body>
        <form id="contact_form">
            <input class="contact_save" type="text" value="" />
        </form>
    </body>
    <script>
        $(document).ready(function($){
            $('#contact_form .contact_save').focusout(function() {
                alert("focusout!");
            });
            $('#contact_form .contact_save').keyup(function() {
                alert("keyup!");
            });
        });
    </script>
</html>

What I am doing wrong? 我做错了什么?

Thanks 谢谢

Michael 迈克尔

It's because the alert causes the focusout to be called. 这是因为警报会导致调出焦点。 Putting the result in another element for an example does not cause it to trigger: 将结果放在另一个元素中作为示例不会导致它触发:

 $('#contact_form .contact_save').focusout(function() { alert("focusout!"); }); $('#contact_form .contact_save').keyup(function() { $('#result').val('keyup'); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="contact_form"> <input class="contact_save" type="text" value="" /> <output id="result" /> </form> 

Trying using: 尝试使用:

$('#contact_form .contact_save').blur(function() {
    alert("focusout!");
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM