凌的博客

您现在的位置是: 首页 > 前端学习 > Js > 

Js

Math.random()获取随机字符串和随机颜色

2024-09-24 Js 25
// 获取随机颜色
function getRandColor(){
    return '#'+Math.random().toString(16).slice(2,6).padEnd(6,'0');
}


// 获取随机字符串
function getRandString(len){
    return Math.random().toString(36).slice(2,2+len).padEnd(len,'0')
}


文章评论

0条评论