Loading

jquery|js|jq常用正则

var mobReg=/^1[34578]\d{9}$/;  //手机号
if (!mobReg.test(mob)) {
    alert("请填写正确手机号!");
};
var telReg=/^0\d{2,3}-?\d{7,8}$/;  //电话号码
if (!telReg.test(tel)) {
    alert("请填写正确电话!");
};
var checkCode = function (val) {
    var p = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
    var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
    var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
    var code = val.substring(17);
    if(p.test(val)) {
        var sum = 0;
        for(var i=0;i<17;i++) {
            sum += val[i]*factor[i];
        }
        if(parity[sum % 11] == code.toUpperCase()) {
            return true;
        }
    }
    return false;
}
if(!checkCode('身份证号')){
    alert("请填写正确的身份证号码!");
}

 下载图片方法

function downloadImage(path,imgName) {
    var _OBJECT_URL;
    var request = new XMLHttpRequest();
    request.addEventListener('readystatechange', function (e) {
        if (request.readyState == 4) {
            _OBJECT_URL = URL.createObjectURL(request.response);
            var $a = $("<a></a>").attr("href", _OBJECT_URL).attr("download", imgName);
            $a[0].click();
        }
    });
    request.responseType = 'blob';
    request.open('get', path);
    request.send();
}

来源:https://www.cnblogs.com/dushaojun/p/11364370.html

 

 

鼠标滚动事件监听,阻止浏览器ctrl加鼠标滚轮页面放大和还原

$(document).ready(function () {
        // chrome 浏览器直接加上下面这个样式就行了,但是ff不识别
        $('body').css('zoom', 'reset');
        $(document).keydown(function (event) {
            //event.metaKey mac的command键
            if ((event.ctrlKey === true || event.metaKey === true)&& (event.which === 61 || event.which === 107 || event.which === 173 || event.which === 109 || event.which === 187  || event.which === 189)){
                event.preventDefault();
            }
        });
        $(window).bind('mousewheel DOMMouseScroll', function (event) {
            if (event.ctrlKey === true || event.metaKey) {
                event.preventDefault();
                var delta = (event.originalEvent.wheelDelta && (event.originalEvent.wheelDelta > 0 ? 1 : -1)) ||  // chrome & ie
                    (event.originalEvent.detail && (event.originalEvent.detail > 0 ? -1 : 1));              // firefox
                if(delta>0){
                    // 上滚动,字体变大
                    $('table').css('font-size',parseInt($('table').css('font-size'))+10+'px');
                }else{
                    // 下滚动,字体变小
                    $('table').css('font-size',parseInt($('table').css('font-size'))-10+'px');
                }
            }

        });
        //当按下ctrl+0键时,还原字体大小
        $(document).keydown(function(event){
            console.log(event);
            if(event.ctrlKey && event.keyCode==96){
                $('table').css('font-size','16px');
            }
        });
    });

 

posted @ 2018-03-15 12:26  王召波  阅读(550)  评论(3编辑  收藏  举报