首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

为何事件触发不了

2013-03-21 
为什么事件触发不了?html xmlnshttp://www.w3.org/1999/xhtmlhead runatservertitle/title

为什么事件触发不了?
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".lowerDiv").hide();
            $(".blockDiv").mouseover(
            function (e) {
                var lowerDiv = document.createElement("div");
                $(lowerDiv).addClass("lowerDiv");
                $(".lowerDiv").show();
                $(".lowerDiv").mouseout(function () {
                    $(".lowerDiv").hide();
                });
            });

        });
    </script>
    <style type="text/css">
        .blockDiv
        {
            border: 1px solid #cccccc;
            background-color: #ababab;
            width: 180px;
            height: 100px;
            position: relative;
        }
        .lowerDiv
        {
            width: 220px;
            height: 140px;
            background-color: Blue;
            position: absolute;
            left: -10px;
            top: -10px;
            z-index: -1;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="blockDiv">
        <table>
            <tr>
                <td>
                    222
                </td>


                <td>
                    33
                </td>
            </tr>
        </table>
        <div class="lowerDiv">
            <input type="button" onclick="alert('');" value="test" style="position: absolute;
                right: 0px; bottom: 0px;" />
        </div>
    </div>
    </form>
</body>
</html>
疑问是:
为什么
$(".lowerDiv").mouseout(function () {
                    $(".lowerDiv").hide();
                });
事件触发不了?
[解决办法]
我知道你要的是什么效果,但是现在问题是你这样的结构没办法实现啊。。
z-index:-1触发不到任何鼠标事件了。

改成这样,多简单。。外面套一层就是


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://nx.snail.com/page/js/lib/jquery-1.8.3.min.js"></script>
    <script type="text/javascript">
        $(function(){
            $(".lowerDiv").hide();
            $(".blockDiv").mouseover(function() {
                $(".lowerDiv").show();
            });
            $(".lowerDiv").mouseenter(function () {
                $(".lowerDiv").hide();
            });
        });
    </script>
    <style type="text/css">
        .blockDiv{
            border: 1px solid #cccccc;
            background-color: #ababab;
            width: 180px;
            height: 100px;
            position: absolute;
            z-index:2;
        }
        .lowerDiv {
            width: 220px;
            height: 140px;


            background-color: Blue;
            position: absolute;
            left: -10px;
            top: -10px;
            z-index:1;
        }
        .container{
            position: relative;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="container">
        <div class="blockDiv">
            <table>
                <tr>
                    <td>
                        222
                    </td>
                    <td>
                        33
                    </td>
                </tr>
            </table>
        </div>
        <div class="lowerDiv">
            <input type="button" onclick="alert();" value="test" style="position: absolute;
                right: 0px; bottom: 0px;" />
        </div>
    </div>
    </form>
    <div id="div1" style="background:yellow; height:100px; width:100px;"></div>
</body>
</html>

热点排行