码迷,mamicode.com
首页 > Web开发 > 详细

html5_common.js

时间:2015-09-01 12:04:51      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

(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*$/, ‘‘);
    }    
})();

 

html5_common.js

标签:

原文地址:http://www.cnblogs.com/chy1000/p/4775134.html

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