没事写着玩 系列之 JQ连连看(很丑陋,很初级)

说明:(图片自备, 名称为 jpg[0,2].jpg  class为( one two three)对应 前面的 0,1,2)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            var imgClass = "null";
            function hideTishi() {

                if ($("#tishi").attr("display") == "block") {

                    $("#tishi").hide("1000");
                }

            }
            //    setInterval("hideTishi()", "2000");
            var errorCounts = 0;


         
            var rows = 7, columns = 7;

            for (var i = 0; i < rows; i++) {

                $("table").append("<tr></tr>");
                for (var j = 0; j < columns; j++) {

                    var root = Math.random();
                    var s = root * 10;
                    var num = s % 2;
                    var classes = "";

                    switch (Math.round(num)) {
                        case 0: classes = "one"; break;
                        case 1: classes = "two"; break;
                        case 2: classes = "three"; break;

                    }


                    var html = "<td><img src=\"img/" + Math.round(num) + ".jpg\" class=\"" + classes + "\" /></td>";
                    $("table").find("tr:eq(" + i + ")").append(html);

                }

            }

 

 

 

            $("img").click(function () {

                $("#tishi").hide("1000");
                //初次点击
                if (imgClass == "null") {
                    imgClass = $(this).attr("class");


                }

                //两次点的图片相同
                if ($(this).attr("class") == imgClass) {
                    $(this).attr("state", "click");
                }
                else {//两次点击不同时


                    $("[state]").removeAttr("state");

                    $("#tishi").show("2000");


                    $("#errorCount").val("当前错误" + parseInt(errorCounts + 1, 10) + "次");
                    errorCounts += 1;

                    imgClass = "null";
                }

                if ($("[state]").length > 1) {

                    while ($("[state]").length > 0) {

                        var img = $("[state]");
                        img.hide("1000");
                        img.removeAttr("state");
                        imgClass = "null";
                        jindu += 1;

                    }

                }

            })

 

 


        })
   
   
    </script>
    <style type="text/css">
        .one, .two, .three
        {
            width: 80px;
            height: 80px;
        }
    </style>
</head>
<body>
    <input type="button" id="tishi" style="border: none; font-size: 20px; display: none;"
        value="两次不一样,请从新选择从选" />
    <input type="button" id="errorCount" style="font-size: 20px; color: Red; position: absolute;
        top: 0px; left: 300px;" count="0" value="当前错误0次" />
    <table style="position: absolute; top: 40px;">
    </table>
</body>
</html>

转载于:https://www.cnblogs.com/Mr-Joe/archive/2012/03/19/2405507.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值