标题:jquery 阻止click,mouseover,mouseout冒泡问题
只看楼主
ab382717036
Rank: 2
等 级:论坛游民
帖 子:73
专家分:20
注 册:2011-3-19
结帖率:91.67%
 问题点数:0 回复次数:0 
jquery 阻止click,mouseover,mouseout冒泡问题
<ul>
                <li class="red"><a href="javascript:void(0)">项目一</a></li>
                <li class="green"><a href="javascript:void(0)">项目二</a></li>
                <li class="green"><a href="javascript:void(0)">项目三</a></li>
                <li class="green"><a href="javascript:void(0)">项目四</a></li>
            </ul>

 $(function () {
            $.each($("li"), function (i, o) {
                $(this).children("a").click(function () {
                    allhide();
                    $(this).parent("li").attr("class", "red");
                });
                if ($(this).attr("class") != "red") {
                    $(this).mouseenter(function () {
                        $(this).attr("class", "red");
                    });
                    $(this).mouseleave(function () {
                        $(this).attr("class", "green");
                    });
                }
            });
        });
        function allhide() {
            $.each($("li"), function (i, o) {
                $(this).attr("class", "green");
            });
        }
 <style type="text/css">
        li
        {
            width: 80px;
            list-style-type: none;
        }
        .red
        {
            background-color: Red;
        }
        .green
        {
            background-color: Green;
        }
    </style>
搜索更多相关主题的帖子: javascript void function children 
2013-04-10 14:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-403621-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.337112 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved