javascript 如果光标在jquery中的输入标签之外,如何设置事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12701252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 16:55:09  来源:igfitidea点击:

how to set event if cursor is out of an input tag in jquery

javascriptjquery

提问by cfz

im new to jquery and i want to know how to get value of an input tag when a cursor is out/left to that input element/tag. Thank you in advance.

我是 jquery 的新手,我想知道当光标离开/离开该输入元素/标签时如何获取输入标签的值。先感谢您。

回答by Sushanth --

Use blurevent

使用模糊事件

 $(function() {
    $('input[type="text"]').on('blur' , function() {
        // Your code here
    });
  });

CHECK DEMO

检查演示

回答by juanOS

I think the method you're searching is focusout

我认为您正在搜索的方法是focusout

$(function() {
    $('#input-element').focusout(function() {
        // put your code here!
    });
});

I hope it helps.

我希望它有帮助。

回答by thomasbabuj

<form>
  <input id="target" type="text" value="Field 1" />
  <input type="text" value="Field 2" />
</form>
<div id="other">
  Trigger the handler
</div>
<script>

$('#target').blur(function() {
  alert('Handler for .blur() called.');
});