js 点击div生成一个随机圆,点击生成的圆再生成另一个随机圆,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
width: 100px;
height: 100px;
background: gold;
border-radius: 50%;
}
</style>
</head>
<body>
<div class="box"></div>
<script>
var box = document.getElementsByClassName('box')[0]
box.onclick = function () {
run(this)
}
function run(target) {
var obj = target.cloneNode()
obj.style.position = 'absolute'
obj.style.left = Math.random() * 1900 + 'px'
obj.style.top = Math.random() * 900 + 'px'
obj.style.background = 'rgb(' + Math.random() * 255 + ',' + Math.random() * 255 + ',' + Math.random() * 255 + ')'
var val = Math.random() * 80 + 20 + 'px'
obj.style.width = val
obj.style.height = val
obj.onclick = function () {
run(obj)
}
document.body.appendChild(obj)
}
</script>
</body>
</html>
