公交车上荫蒂添的好舒服的电影-公用玩物(np双xing总受)-公用小荡货芊芊-公与妇仑乱hd-攻把受做哭边走边肉楼梯play-古装一级淫片a免费播放口

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

19個基本 JavaScript 方法

admin
2024年10月13日 22:43 本文熱度 914

?

01.函數(shù)節(jié)流

/** Function throttling timer version */function throttle(callback: Function, delay: number) {   let timer: number | null   return function () {     if (timer) return     const args = arguments //Use closure to save parameter array     timer = setTimeout(() => {       callback.apply(null, args)       timer = null     }, delay)   }}

02.URL 解碼和編碼

/** Encode URL */function encodeURL(url: string, isComponent = true): string {   return isComponent ? encodeURIComponent(url) : encodeURI(url)}
/** Decode URL */function decodeURL(url: string, isComponent = true): string {   return isComponent ? decodeURIComponent(url) : decodeURI(url)}

03.使用JavaScript 獲取全局 CSS 變量

/** * @description Use JS to get global css variables * @param cssVariableName variable name * @returns {string} variable value*/function getCssVariableValue(cssVariableName: string): string {   return getComputedStyle(document.documentElement).getPropertyValue(cssVariableName)}

04.使用 JS 設(shè)置全局 CSS 變量

/**  * @description Set global CSS variables with JS  * @param {string} cssVariableName variable name  * @param {string} cssVariableValue variable value  */function setCssVariableValue(cssVariableName: string, cssVariableValue: string): void {   document.documentElement.style.setProperty(cssVariableName, cssVariableValue)}

05.清除所有 cookies 

/** * @description clear all cookies */function clearCookie(): void {   const keyList = document.cookie.match(/[^ =;]+(?=\=)/g) as string[] | null   keyList && keyList.forEach(key => (document.cookie = `${key}=0;path=/;expires=${new Date(0).toUTCString()}`))}

06.清除所有項目緩存

/** * @description Clear all project caches */function clearCache(): void {  window.localStorage.clear()  window.sessionStorage.clear()  const keyList = document.cookie.match(/[^ =;]+(?=\=)/g) as string[] | null  keyList && keyList.forEach(key => (document.cookie = `${key}=0;path=/;expires=${new Date(0).toUTCString()}`))}

07.通過名稱獲取 URL 查詢參數(shù) 

/**  * @description Get URL query parameters by name  * @param {string} key The key of the query parameter that needs to be obtained  * @param {string} url The link that needs to be parsed, the default is window.location.href  * @returns {string | null} obtained value corresponding to key  */function getQueryByName(key, url = window.location.href) {   const queryNameRegExp = new RegExp(`[?&]${key}=([^&]*)(?:&|$)`)   const queryNameMatch = url.match(queryNameRegExp)   return queryNameMatch ? decodeURIComponent(queryNameMatch[1]) : null}

08.登錄頁面時間前綴

/**  * @description time prefix of login page  * @returns {string} time prefix  */function timeFix(): string {   const time = new Date()   const hour = time.getHours()   return hour < 9 ? 'Good morning' : hour <= 11 ? 'Good morning' : hour <= 13 ? 'Good afternoon' : hour < 20 ? 'Good afternoon' : 'Good evening'}

09.登錄頁面上的歡迎信息

/**  * @description Welcome message on the login page  * @returns {string} random welcome message  */function welcome(): string {   const list = ['Long time no see, I miss you so much! ', 'Wait until the stars go to sleep before I miss you', 'We are open today']   return list[Math.floor(Math.random() * list.length)]}

10.遞歸深層復(fù)制

/**  * @description Make a deep copy of the incoming data and return it  * @param {any} source data source  * @returns {any} copied data  */function deepClone(source: any): any {   if (!source || typeof source !== 'object') return source   if (source instanceof Date) return new Date(source)   if (source instanceof RegExp) return new RegExp(source)   const target = Array.isArray(source) ? ([] as Record<any, any>) : ({} as Record<any, any>)   for (const key in source) target[key] = typeof source[key] === 'object' ? deepClone(source[key]) : source[key]   return target}

11.隨機生成一個 UUID 

/**  * @description Randomly generate a UUID  * @returns {string} generated uuid  */function getRandomUUID(): string {   const tempURL = URL.createObjectURL(new Blob())   const uuidStr = tempURL.toString()   const separator = uuidStr.includes('/') ? '/' : ':'   URL.revokeObjectURL(tempURL)   return uuidStr.substring(uuidStr.lastIndexOf(separator) + 1)}
function getRandomUUID(): string {   const fn = (): string => (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)   return fn() + fn() + '-' + fn() + '-' + fn() + '-' + fn() + '-' + fn() + fn() + fn()}

12.隨機布爾值

/**  * @description random boolean value  * @returns {boolean} true | false  */function getRandomBoolean(): boolean {   return Math.random() > 0.5}

13.反轉(zhuǎn)字符串

/**  * @description reverse string  * @param {string} str string  * @returns {string} reversed string  */function reverseString(str: string): string {   return str.split('').reverse().join('')}

14.隨機生成十六進(jìn)制顏色

/**  * @description Randomly generates a color string in Hex format  * @returns {string} Color string in Hex format  */function getRandomHexColor(): string {   return `#${Math.floor(Math.random() * 0xffffff).toString(16)}`}

15.獲取變量的真實類型

/**  * @description Get the real type of the variable  * @param {any} variable variable of any type  * @returns {string} variable type  */function getRawType(variable: any): string {   return Object.prototype.toString.call(variable).split(' ')[1].replace(']', '').toLowerCase()}

16.將文本復(fù)制到剪貼板

/**  * @description Copy text to clipboard  * @param {string} text The copied text  */function copyText(text: string): void {   // Whether to support navigator.clipboard attribute   const isClipboardApiSupported = window.navigator && window.navigator.clipboard   if (isClipboardApiSupported) {     window.navigator.clipboard.writeText(text)   } else {     const textarea = document.createElement('textarea')     textarea.readOnly = true     textarea.value = text     textarea.style.position = 'absolute'     textarea.style.top = '-9999px'     textarea.style.left = '-9999px'     document.body.appendChild(textarea)     textarea.select()     document.execCommand('copy')     textarea.remove()   }}

17.滾動到頂部

/**  * @description scroll to top  */function scrollToTop(element: HTMLElement): void {   element.scrollIntoView({ behavior: 'smooth', block: 'start' })}

18.滾動到底部

/** * @description scroll to bottom */function scrollToBottom(element: HTMLElement): void {  element.scrollIntoView({ behavior: 'smooth', block: 'end' })}

19.對象公共方法

const obj = { a: 1, b: 2, c: 3, d: 4 }//Object.keys()// Will return an array consisting of the given object's own enumerable propertiesObject.keys(obj) // ['a', 'b', 'c', 'd']//Object.values()// Returns an array of all enumerable property values of the given object itselfObject.values(obj) // [1, 2, 3, 4]//Object.entries()// Returns an array of key-value pairs for the given object's own enumerable propertiesObject.entries(obj) // [['a', 1], ['b', 2], ['c', 3], ['d', 4]]//Object.fromEntries()//Convert the list of key-value pairs into an object, which is the reverse operation of Object.entries()Object.fromEntries( [['a', 1], ['b', 2]]) // { a: 1, b: 2 }// hasOwnProperty()// Returns a Boolean value indicating whether the object has the specified attribute in its own properties (that is, whether it has the specified key)obj.hasOwnProperty('a') // trueobj.hasOwnProperty('fff') // false//Object.assign()// Used to copy the values of all enumerable properties from one or more source objects to the target object. It will return the target object.const target = { a: 1, b: 2 }const source = { b: 4, c: 5 }const result = Object.assign(target, source) // { ...target, ...source } has the same effectconsole.log(result) // {a: 1, b: 4, c: 5}


該文章在 2024/10/14 10:50:31 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運作、調(diào)度、堆場、車隊、財務(wù)費用、相關(guān)報表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點,圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務(wù)都免費,不限功能、不限時間、不限用戶的免費OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

主站蜘蛛池模板: 国产一区在线播放网址 | 国产无码在线视频高清无删减 | 国产精品美乳在线观看 | 国产午夜激无码色本v毛片 国产午夜精华2025在线 | 国产白浆视频 | 精品久久久久久中文字幕无码软件 | av资源免费| 国产日韩久久久久精品影视 | 国产精品视频一区日韩丝袜 | 国产日韩久久久久无码精品 | 国产精品免费久久久久久蜜桃 | 成年永久一区三区免费视频 | 福利小电影在线看 | av鲁丝一区鲁丝二区鲁丝三区 | 国产av无码乱码国产精品 | 国产精品皮裤在线观看 | av电影在线观看 | 18禁美女黄网站色大片免费看下 | 成在线人视频免费视频 | 国产高清亚洲一区二区三区 | 国产免费无码av片在线观看不卡 | 91视频网站如何满足用户需求 | 国产av影视 | 国产白丝无码免费视频 | 精品久久久久久清纯 | 国产成人无码aⅴ片在线观看不卡 | 国产三级在线免费观看 | 成年女人视频网站免费m | 国产精品毛片无遮挡高清 | 精品少妇爆乳无码专区久久 | 国产成人免费永 | 91精品!在线观看不卡视频 | 国产肥熟老胖女在线看 | av嗯啊| 18禁裸乳无遮挡免费观看 | 国产成人精品亚洲高清在线 | 国产精品亚洲a∨天堂 | 国产精品边做奶水狂喷无码 | 国产成人深夜福利在线观 | 精品丝袜国产在线播放 | 99久久精品免费精品国产 |