[英]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.