当前位置: 代码迷 >> JavaScript >> jquery 阻止click,mouseover,mouseout冒泡有关问题
  详细解决方案

jquery 阻止click,mouseover,mouseout冒泡有关问题

热度:298   发布时间:2013-04-21 21:18:07.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;
  相关解决方案