繁体   English   中英

如何知道何时 <input> 元素已使用jQuery取消选择

[英]How to know when an <input> element has been deselected using jQuery

一旦两个不同的字段中都有值,我就会尝试执行一些验证。 我当前用于输入字段之一的代码如下所示:

$("#project1").focusout(function () {
    if (projLoc && projLoc.value) {
        projEntered = true;
        console.log("project entered in row " + row);
        if (projEntered && taskEntered) {
            Validate();
        }
    }
    else {
        projEntered = false;
    }
});

当文本输入字段中有值并且输入字段已取消选择时,我想将boolean projEntered的值projEntered为true。

使用http://api.jquery.com/blur/中的 .blur()

 $( "#target" ).blur(function() { alert( "Handler for .blur() called." ); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form> <input id="target" type="text" value="Field 1"> <input type="text" value="Field 2"> </form> 

从片段中可以看到,当Field 1失去焦点时,将调用blur()

暂无
暂无

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

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