JQuery 停止事件冒泡

来源:互联网 发布:淘宝隐形降权怎么解决 编辑:程序博客网 时间:2024/04/30 07:40
<!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 runat="server">
    <title></title>

    <script src="jquery-1.3.2.min.js" type="text/javascript"></script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tbody>
                <tr>
                    <td>
                        事件冒泡
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    </form>

    <script type="text/javascript">
        $(document).ready(function() {
            $("tbody").click(function() {
                alert("tbody");
            });
            $("tr").click(function() {
                alert("tr");
            });
            $("td").click(function(e) {
                alert("td");
                //停止事件冒泡
                e.stopPropagation();
            });
        });
    </script>

</body>
</html>