for循环⽣成10个li
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
padding:0;
margin:0;
}
ul li {
width:20px;
height:20px;
margin:20px;
typeof array
display: inline-block;
text-align: center;
}
</style>
</head>
<script src="/js/jquery.js">
</script>
<body>
<button>点击猜猜有什么10</button>
<ul class="list"></ul>
<script>
$('button').click(function(e){
var color =["blue","purple","pink","yellow","green","red",'#008c8c','white']
e.preventDefault();
for(let i =0; i <10; i++){
var mli=$(`<li>${i+1}</li>`)
//0-7
mli.css('color',color[Math.floor(Math.random()*8)]);
mli.appendTo($('ul'))
}
});
</script>
</body>
</html>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。