jq 抽奖

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
ul{ width:328px;}
li{ width:100px; height:100px; border:1px #000 solid; float:left; margin-left:5px; list-style:none;}
.active{ background:red;}
</style>
<script src="jquery-1.11.1.js"></script>
<script>
$(function(){
    
    var iNow = 0;
    
    $('input').click(function(){
        var step = parseInt(Math.random() * 20 + 5);
        var timer = setInterval(function(){
            $('li').attr('class','');
            $('li').eq(iNow).attr('class','active');
            iNow++;
            step--;
            if(step==0){
                clearInterval(timer);
                alert( '您抽到了:' + $('li[class=active]').html() );
            }
            if(iNow == $('li').length){
                iNow = 0;
            }
        },100);
        
        $()
        
    });
    
});
</script>
</head>

<body>
<input type="button" value="抽奖">
<ul>
    <li>1等奖</li>
    <li>2等奖</li>
    <li>3等奖</li>
    <li>4等奖</li>
    <li>5等奖</li>
    <li>6等奖</li>
    <li>7等奖</li>
    <li>8等奖</li>
    <li>9等奖</li>
</ul>
</body>
</html>

 

posted @ 2015-04-16 20:40  miyaye  阅读(185)  评论(0编辑  收藏  举报