小编Phi*_*ice的帖子

Jquery Onclick 不再发生第二次

我有点困惑为什么这不起作用;我认为因为我正在添加该类并且它没有被添加回集合中,所以我不确定。

它位于 jsbin http://jsbin.com/ayije上,尽管代码也在下面。

无论哪种方式,我只能让该操作在一个元素上发生一次。

<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript" charset="utf-8">
        $(document).ready(function () {
            $('.optional').click(function () {
                $(this).removeClass('optional').addClass('selected');
                return false;
            }); 
            $('.selected').click(function () {
                $(this).removeClass('selected').addClass('rejected');
                return false;
            });
            $('.rejected').click(function () {
                $(this).removeClass('rejected').addClass('optional');
                return false;
            });
        });
        </script>
    </head>
    <body>
        <style>
            a {padding:2px;color:white;}
            .optional {background-color:blue;}
            .selected {background-color:green;}
            .rejected {background-color:red;}
        </style>


        <div id="tagContainer"> 
        <a href="#" class="rejected">a</a>
        <a href="#" class="optional"">b</a>
        <a href="#" class="selected">c</a>
    </div>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

iteration collections jquery click repeat

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

click ×1

collections ×1

iteration ×1

jquery ×1

repeat ×1