JS效果功能_百宝箱

平台实时监控平台,统计报错数

window.onerror = function(a,b,c,d,e){
	(new Image).src = '/m?p=${location.href}&a=${a}&b=${b}&c=${c}&d=${d}&e=${e.statck}'
}

Linux 打印日志输出

tail -f access.log function curentTime(){ 
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var day = now.getDate();
    var hh = now.getHours();
    var mm = now.getMinutes();
    var ss = now.getSeconds();

    var clock = year + "-";
    if(month < 10) clock += "0";
    clock += month + "-";
   
    if(day < 10) clock += "0";
    clock += day + " ";
   
    if(hh < 10) clock += "0";  
    clock += hh + ":";

    if (mm < 10) clock += '0'; 
    clock += mm + ":";

    if (ss < 10) clock += '0'; 
    clock += ss; 

    return(clock);                                                                                                      

剔除字符串中的HTML标签

if(typeof(String.prototype.removeHTMLTag) == "undefined"){
  String.prototype.removeHTMLTag = function(){
	return this.replace(/<.+?>([^<>]+?)<.+?>/g, '$1');
  }
}

var str = "<span name='233241' id=2341>张酝</span><span name='233241' id=2341>张酝AAA</span>";
var s   = str.removeHTMLTag();
console.log(s); 

禁用页面菜单js代码

<script type="text/javascript">
document.oncontextmenu=function(){ return false; }
</script>

oncontextmenu 事件

注意:所有浏览器都支持 oncontextmenu 事件, contextmenu 元素只有 Firefox 浏览器支持。

HTML 中:
<element oncontextmenu="myScript">

JavaScript 中:
object.oncontextmenu=function(){myScript};

JavaScript 中, 使用 addEventListener() 方法:
object.addEventListener("contextmenu", myScript);

 

如何设置body内容不能复制?

<body oncontextmenu="return false" 
    ondragstart="return false"
    onbeforecopy="return false"
    oncopy="document.selection.empty()"
onselect="document.selection.empty()"
onselectstart="return false">

 

JS编写定时器

$(function(){
    timer();
    function timer(settings){
        var config = {
            days :$('#days'),
            hours: $('#hours'),
            minutes: $('#minutes'),
            seconds: $('#seconds'),
            interval: 1000,
        };
        function prependZero(number){
            return number < 10 ? '0' + number : number;
        }
         var time=new Date();
           var days=time.getDate();
           var hours=time.getHours();
           var minutes=time.getMinutes();
           var seconds=time.getSeconds();        
            config.days.text(prependZero(days));
            config.hours.text(prependZero(hours));
            config.minutes.text(prependZero(minutes));
            config.seconds.text(prependZero(seconds));
       $('.days').css('display', 'inline-block');
       $('.hours').css('display', 'inline-block');
       $('.minutes').css('display', 'inline-block');
       $('.seconds').css('display', 'inline-block');
        var intervalID = setInterval(function(){
           var time=new Date();
           var days=time.getDate();
           var hours=time.getHours();
           var minutes=time.getMinutes();
           var seconds=time.getSeconds();        
            config.days.text(prependZero(days));
            config.hours.text(prependZero(hours));
            config.minutes.text(prependZero(minutes));
            config.seconds.text(prependZero(seconds));
        }, config.interval);
    }
});

 

兼容PC端和移动端Click事件和touch事件

var nav4 =(function(){
    bindClick = function(els, mask){
        if(!els || !els.length){return;}
        var isMobile = "ontouchstart" in window;
        for(var i=0,ci; ci = els[i]; i++){
            ci.addEventListener("click", evtFn, false);
        }

        function evtFn(evt, ci){
            ci =this;
            for(var j=0,cj; cj = els[j]; j++){
                if(cj != ci){
                    console.log(cj);
                    cj.classList.remove("on");
                }
            }
            if(ci == mask){mask.classList.remove("on");return;}
            switch(evt.type){
                case "click":
                    var on = ci.classList.toggle("on");
                    mask.classList[on?"add":"remove"]("on");
                break;
            }
        }
        mask.addEventListener(isMobile?"touchstart":"click", evtFn, false);
    }
    return {"bindClick":bindClick};
})();

 

posted @ 2018-07-09 10:27  心无引擎,眼无流派  阅读(381)  评论(0)    收藏  举报