惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
C
Check Point Blog
G
Google Developers Blog
V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
有赞技术团队
有赞技术团队
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
D
Docker
Hugging Face - Blog
Hugging Face - Blog
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
Recent Announcements
Recent Announcements
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News

博客园 - 三聪

流操作 如何利用.Net内置类,解析未知复杂Json对象 制作等比环切缩缩图 让window.setTimeout等支持带参数方法 利用NewID()生成随机数 创建缩略图 winform给html提供接口 IE下记住文本框的光标位置 ie下取得iframe里面内容 短网址计算 树冲突 截图片 学习Objective-C: 入门教程 C#根据字节数截取字符串 asp.net本地和全局资料文件的读取方法 Asp.net 利用Jquery Ajax传送和接收DataTable 用一个最简单方法解决asp.net页面刷新导致数据的重复提交 SOS"未将对象引用设置到对象的实例" .NET调PHP Web Service的典型例子
jquery实现点击空白的事件
三聪 · 2010-11-04 · via 博客园 - 三聪

//点击空白扩展
jQuery.fn.extend({
    clickOther: 
function() {
        
if (window.click_other == null) {
            window.click_other 
= new Array();
        }
        window.click_other.push({ target: 
this, func: arguments[0] });
        $(document.body).click(
function(e) {
            
for (var i = 0; i < click_other.length; i++) {
                
var item = window.click_other[i];
                
var target = item.target;
                
if (typeof (target) == "String") target = $(target)[0];if (e.target == target) {
                    
continue;
                }
                
var index = $(e.target).parents().index(target);
                
if (index == -1) {
                    item.func();
                }
            }
        });

    },
    unClickOther: 

function() {
        
if (window.click_other == null) {
            
return;
        }
        
for (var i = 0; i < window.click_other.length; i++) {
            
var item = window.click_other[i];
            
if (item.target == this) {
                window.click_other.splice(i, 
1);
            }
        }
    }
}); 

//点击空白扩展
jQuery.fn.extend({
    clickOther: 
function() {
        
function isInside(e, target) {
            
var x = e.pageX;
            
var y = e.pageY;
            
var left = target.offset().left;
            
var width = target.width();
            
var top = target.offset().top;
            
var height = target.height();if (x > left && x < left + width && y > top && y < top + height) return true;
            
return false;
        }
        
if (window.click_other == null) {
            window.click_other 
= new Array();
        }
        
this.except = null;
        
var func = arguments[0];
        
if (typeof (func) == "string") {
            
this.except = document.getElementById(func);
            func 
= arguments[1];
        }
        window.click_other.push({ target: 
this, func: func });
        $(document).click(
function(e) {
            
for (var i = 0; i < click_other.length; i++) {
                
var item = window.click_other[i];
                
var target = $(item.target);
                
if (isInside(e, target)) continue;
                
if (item.target.except) {
                    
var except = $(item.target.except);
                    
if (isInside(e, except)) continue;
                }
                item.func();
            }
        });

    },
    unclickOther: 

function() {
        
if (window.click_other == null) {
            
return;
        }
        
for (var i = 0; i < window.click_other.length; i++) {
            
var item = window.click_other[i];
            
if (item.target == this) {
                window.click_other.splice(i, 
1);
                
break;
            }
        }
    }
});