zoukankan      html  css  js  c++  java
  • 常用函数

    去重:

    1. (两个es6知识点set/...)

    let arr = [1,2,3,4,1];
    let set = new Set(arr)
    // set 转 arr
    let arr2 = [...set];

    let arr3 = Array.from(set)

    copyToClipboard - 复制到剪贴板

    const copyToClipboard = str => {
      const el = document.createElement('textarea');
      el.value = str;
      el.setAttribute('readonly', '');
      el.style.position = 'absolute';
      el.style.left = '-9999px';
      document.body.appendChild(el);
      const selected =
        document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
      el.select();
      document.execCommand('copy');
      document.body.removeChild(el);
      if (selected) {
        document.getSelection().removeAllRanges();
        document.getSelection().addRange(selected);
      }
    };

    回到顶部:
    const scrollToTop = () => {
      const c = document.documentElement.scrollTop || document.body.scrollTop;
      if (c > 0) {
        window.requestAnimationFrame(scrollToTop);
        window.scrollTo(0, c - c / 8);
      }
    };
    ps:
    scrollTo=scroll(但是官网建议频次高的话用scrollTop,scrollBy是相对定位)


     function param2Obj(url) {
            const search = url.split('?')[1]
            if (!search) {
                return {}
            }
            return JSON.parse(
                '{"' +
                decodeURIComponent(search)
                    .replace(/"/g, '\"')
                    .replace(/&/g, '","')
                    .replace(/=/g, '":"') +
                '"}'
            )
        }
        function setCookie(cname, cvalue, exdays) {
          var d = new Date();
          d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
          document.cookie = `${cname}=${cvalue};expires=${d}}`;
        }
        function getCookie(cname){
            var ca = document.cookie.split(';');
            var name = cname +'=';
            for(var i=0;i<ca.length;i++){
                var c = ca[i];
                if(c.indexOf(name)==0){
                    return c.substring(name.length,c.length)
                }
            }
        }
    

      

     
  • 相关阅读:
    如何利用python爬虫爬取音乐
    python中文件操作各符号意思
    基于node.js人脸识别之人脸对比
    体感在js中的调用
    了解Github
    初识微信小程序
    Spring中表达式语言spring-expression简单使用
    IDEA对jsr305的Nonnull注解和Guava的Beta注解的支持
    设计模式之访问者模式
    设计模式之桥接模式
  • 原文地址:https://www.cnblogs.com/gggwf/p/8185758.html
Copyright © 2011-2022 走看看