跳至主要內容

10.js开发小技巧

pinia小于 1 分钟

获取URL参数

// 获取url参数
let params = new URLSearchParams(
    window.location.search
);

随机生成颜色

let randomColor1 = `rgba(${Math.floor(Math.random() * 255)}, ${Math.floor(Math.random() * 255)}, ${Math.floor(Math.random() * 255)}, ${Math.random().toFixed(1)})`;
let randomColor2 = `rgb(${Math.floor(Math.random() * 255)}, ${Math.floor(Math.random() * 255)}, ${Math.floor(Math.random() * 255)})`;
let randomColor3 = `#${Math.floor(Math.random() * 16777215).toString(16)}`;

生成指定范围内随机整数

let randomInt = (min, max) => {
    return Math.floor(Math.random() * (max - min + 1) + min);
};
上次编辑于:
贡献者: 林深不见鹿