强制元素在文本框外部单击时隐藏 [英] Force element to hide on click outside of textbox

查看:34
本文介绍了强制元素在文本框外部单击时隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我所拥有的:

$(document).ready(function () {
$('#H-Alert').hide();

$('html').click(function (e) {
    if (e.target.className == '.h-textbox') {
        $('#H-Alert').show();
    }
    else {
        $('#H-Alert').hide();
    }
});
});

我已经引用了这个:

参考

感谢您的帮助.

推荐答案

您可能正在寻找 blur 焦点事件.您可以使用jQuery进行以下操作:

You're probably looking for the blur and focus events. You can do this using jQuery as follows:

$('#H-Alert').hide();
$(window).ready(function(){
    $('.h-textbox').blur(function(){
      $('#H-Alert').show();
    }).focus(function(){
      $('#H-Alert').hide();
    });
});

这篇关于强制元素在文本框外部单击时隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆