码迷,mamicode.com
首页 > 编程语言 > 详细

Javascript

时间:2015-08-31 00:47:10      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

 function on(node,type,funchandler) {
            node = typeof node == "string" ? document.getElementById(node) : node;
            if (!document.all) {
                node.addEventListener(type, funchandler);
            } else {
                node.attachEvent("on"+type,funchandler);
            }
        }

        function trim(ostr) {
            return ostr.replace(/^\s+|\s+$/g, ‘‘);
        }

        function isNumber(s) {
            return !isNaN(s);
        }

        function isString(s) {
            return typeof s == "string";
        }

        function isBoolean(s) {
            return typeof s == ‘boolean‘;
        }

        function isNull(s) {
            return s == null;
        }

        function isUndefined(s) {
            return typeof s == "undefined";
        }

        function isEmpty(s) {
            return /^\s*$/.test(s)
        }

        function isArray(s) {
            return s instanceof Array;
        }

  

 /*
        claaName:类名
        root:根元素
        tag:标签类型
        */
        function getElementsByClassName(claaName, root, tag) {
            var arr = [];
            if (root) {
                root = typeof root == ‘string‘ ? document.getElementById(root) : root;
            } else {
                root = document.body;
            }
            tag = tag || ‘*‘;
            var eles = root.getElementsByTagName(tag);
            for (var i = 0; i < eles.length ; i++) {
                for (var j = 0, k = eles[i].className.split(/\s+/g), l = k.length; j < l; j++) {
                    if (k[j] == claaName) {
                        arr.push(eles[i]);
                        break;
                    }
                }
            }
            return arr;
        }

  

Javascript

标签:

原文地址:http://www.cnblogs.com/alphafly/p/4771893.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!