html5_common.js

(function(){
    this.sendAjax = function(url,func,formData,type){
        type = type || "POST"; //默认为POST的方式
        var xhr = new XMLHttpRequest();
        if( typeof xhr.withCredentials===undefined ){
            return alert("对不起,您的浏览器不支持:XMLHttpRequest");
        }
        
        xhr.onload = func;
        xhr.open(type,url,true);
        if( undefined!==formData ){
            xhr.send(formData);
        }else{
            xhr.send();
        }
    }
    
    this.$one = function(name){
        return document.querySelector(name);
    }

    this.$all = function (name){
        return document.querySelectorAll(name);
    }

    this.stopPropagation = function(e) {  
        e = e || window.event;  
        if(e.stopPropagation) { //W3C阻止冒泡方法  
            e.stopPropagation();  
        } else {  
            e.cancelBubble = true; //IE阻止冒泡方法  
        }  
    }
    
    String.prototype.trim = function() {
        return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    }    
})();

 

posted @ 2015-09-01 10:51  chy1000  阅读(277)  评论(0编辑  收藏  举报