目录

    JS笔记

    • 全屏

        if (element.requestFullscreen) {
          element.requestFullscreen();
        } else if (element.webkitRequestFullscreen) {
          // ios safari
          element.webkitRequestFullscreen();
        }
      
    • js URL转译方法 encodeURIComponent()

        function addQueryParam(url: string, key: string, value: string) {
          const urlObj = new URL(url)
          const params = new URLSearchParams(urlObj.search)
          if (params.has(key)) {
            params.set(key, value)
          } else {
            params.append(key, value)
          }
          urlObj.search = params.toString()
          return urlObj.href
        }
      
    • const toThousands = (num: number) => String(num).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
      
    • console.info(
          '%cThis is My stylish %cThis is My stylish',
          'color: yellow; background-color: #409eff;padding: 4px 12px;border-radius: 4px 0 0 4px;font-weight: 1000;',
          'color: black; background-color: #fff;padding: 4px 12px;border-radius: 0 4px 4px 0;',
      )
      // 了解一下console
      
    • // 创建blob对象
      const text = 'This is a sample text file.'
      const blob = new Blob([text], { type: 'text/plain' })
      // type 值 https://developer.mozilla.org/zh-CN/docs/Web/HTTP/MIME_types/Common_types
      
    • // IIFE (Immediately-Invoked Function Expression)立即执行函数