<div style="color: #fecc0f;">111</div>
<script>
console.log(jzw.rndColor())//随机颜色
console.log(jzw.getLocation())//解码
console.log(jzw.converStr2obj('a=2&c=30'))
</script>
//js部分let jzw = {
getLocation() {
let str = location.search.replace(’?’, ‘’)
return this.converStr2obj(str)
},
converStr2obj(str) {
let obj = {}
str.split(’&’).forEach(item => {
let kv = item.split(’=’)
let key = kv[0]
let val = kv[1]
obj[key] = decodeURI(val)
})
return obj
},
rnd(max, min = 0) {
return Math.round(Math.random() * (max - min) + min)
},
rndColor() {
let str = ‘0123456789ABCDEF’
let color = [’#’]
for (let i = 0; i < 6; i++) {
color.push(str[this.rnd(str.length - 1)])
}
return color.join(’’);
},
}