转自:http://www.jb51.net/article/16290.htm

判断变量是否空值undefined, null, '', false, 0, [], {} 均返回true,否则返回false 

    function isEmpty(v){ 
        switch (typeof v) {
            case 'undefined': return true;
            case 'string': if (trim(v).length == 0) return true; break;
            case 'boolean': if (!v) return true; break;
            case 'number': if (0 === v) return true; break;
            case 'object':
                if (null === v) return true;
                if (undefined !== v.length && v.length == 0) return true;
                for (var k in v) { return false; } return true;
                break;
        }
        return false;
    }



本文转载:CSDN博客