当失去焦点/模糊时隐藏DIV [英] Hide a DIV when it loses focus/blur

查看:95
本文介绍了当失去焦点/模糊时隐藏DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示DIV的JavaScript(将其显示css属性从'none'设置为'normal'。有没有办法让它集中注意力,以便当我点击页面上的其他位置时,DIV会丢失焦点及其显示属性设置为无(基本上隐藏它)。我正在使用JavaScript和jQuery

I have a JavaScript that displays a DIV (sets its display css property from 'none' to 'normal'. Is there a way to give it focus as well so that when I click somewhere else on the page, the DIV loses focus and its display property is set to none (basically hiding it). I'm using JavaScript and jQuery

推荐答案

用于隐藏点击页面上除了selecteddiv之外的任何地方的div

For the hide the div when clicking any where on page except the selecteddiv

$(document).not("#selecteddiv").click(function() {
        $('#selecteddiv').hide();
    });

如果你想隐藏焦点丢失或模糊动画的div,那么

if you want to hide the div with lost focus or blur with animation then also

$("#selecteddiv").focusout(function() {
        $('#selecteddiv').hide();
    });

带动画

$("#selecteddiv").focusout(function() {
    $('#selecteddiv').animate({
        display:"none"
    });
});

这可以帮助你

这篇关于当失去焦点/模糊时隐藏DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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