87,910
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<script src="http://code.jquery.com/jquery-1.8.3.min.js "></script>
<style type="text/css">
div{
display: none;
}
</style>
</head>
<body>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
<div>16</div>
<div>17</div>
<div>18</div>
<div>19</div>
<div>20</div>
<button id="changeBtn" type="button">换一批</button>
</body>
</html>
<script type="text/javascript">
$(function() {
sjShow();
$("#changeBtn").click(function(){
sjShow();
});
})
function sjShow(){
$("div").hide();
var showCount=0;
while(showCount<8){
var id=Math.floor(Math.random()*20);
var curDiv=$("div").eq(id);
if(curDiv.css("display")=="none"){
curDiv.css("display","block");
showCount++;
}
}
}
</script>