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

推荐订阅源

J
Java Code Geeks
M
MIT News - Artificial intelligence
D
Docker
S
SegmentFault 最新的问题
B
Blog
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
C
Check Point Blog
GbyAI
GbyAI
美团技术团队
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog

博客园 - 三聪

流操作 如何利用.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;
            }
        }
    }
});