js实现左键弹出式菜单


左键弹出式菜单[推荐][修改显示的文字及链接即可][共2步]

====1、将以下代码加入HEML的之间:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<style type="text/css">
body {
    font9pt "宋体";
    margintop: 0px;
    color#ffffff;
    background#000000
}

a. {
    font9pt "宋体";
    cursor: hand;
    font-size9pt;
    color#ffffff;
    text-decoration: none
}

a:active {
    font9pt "宋体";
    cursor: hand;
    color#FF0033
}

a.cc:hover {
    font9pt "宋体";
    cursor: hand;
    color#FF0033
}

.box {
    font9pt "宋体";
    position: absolute;
    background#000000
}
</style>

====2、将以下代码加入到HEML的之间:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<table id="itemopen" class="box" style="display:none">
    <tr>
        <td>弹出菜单</td>
    </tr>
    <tr>
        <td><a href="../../../index.html" class="cc">本站首页</a></td>
    </tr>
    <tr>
        <td><a href="../../navigation/newscript.htm" class="cc">最新更新</a></td>
    </tr>
    <tr>
        <td><a href="../../navigation/applet/appletindex.htm" class="cc">梦想软件</a></td>
    </tr>
    <tr>
        <td><a href="../../../jsschool/index.htm" class="cc">桌面壁纸</a></td>
    </tr>
    <tr>
        <td><a href="popmenu.htm" class="cc">更多连接</a></td>
    </tr>
    <tr>
        <td><a href="popmenu.htm" class="cc">更多连接</a></td>
    </tr>
    <tr>
        <td><a href="popmenu.htm" class="cc">更多连接</a></td>
    </tr>
</table>
``````javascript
<script language="JavaScript">
document.onclick = popUp
function popUp() {
    newX = window.event.x + document.body.scrollLeft
    newY = window.event.y + document.body.scrollTop
    menu = document.all.itemopen
    if (menu.style.display == "") {
        menu.style.display = "none"
    } else {
        menu.style.display = ""
    }
    menu.style.pixelLeft = newX - 50
    menu.style.pixelTop = newY - 50
}
</script>

完整源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    <style type="text/css">
    body {
        font: 9pt "宋体";
        margintop: 0px;
        color: #ffffff;
        background: #000000
    }
    
    a. {
        font: 9pt "宋体";
        cursor: hand;
        font-size: 9pt;
        color: #ffffff;
        text-decoration: none
    }
    
    a:active {
        font: 9pt "宋体";
        cursor: hand;
        color: #FF0033
    }
    
    a.cc:hover {
        font: 9pt "宋体";
        cursor: hand;
        color: #FF0033
    }
    
    .box {
        font: 9pt "宋体";
        position: absolute;
        background: #000000
    }
    </style>
</head>

<body>
    <table id="itemopen" class="box" style="display:none">
        <tr>
            <td>弹出菜单</td>
        </tr>
        <tr>
            <td><a href="../../../index.html" class="cc">本站首页</a></td>
        </tr>
        <tr>
            <td><a href="../../navigation/newscript.htm" class="cc">最新更新</a></td>
        </tr>
        <tr>
            <td><a href="../../navigation/applet/appletindex.htm" class="cc">梦想软件</a></td>
        </tr>
        <tr>
            <td><a href="../../../jsschool/index.htm" class="cc">桌面壁纸</a></td>
        </tr>
        <tr>
            <td><a href="popmenu.htm" class="cc">更多连接</a></td>
        </tr>
        <tr>
            <td><a href="popmenu.htm" class="cc">更多连接</a></td>
        </tr>
        <tr>
            <td><a href="popmenu.htm" class="cc">更多连接</a></td>
        </tr>
    </table>
    <!-- End of Popup Menu -->
    <script language="JavaScript">
    document.onclick = popUp
    function popUp() {
        newX = window.event.x + document.body.scrollLeft
        newY = window.event.y + document.body.scrollTop
        menu = document.all.itemopen
        if (menu.style.display == "") {
            menu.style.display = "none"
        } else {
            menu.style.display = ""
        }
        menu.style.pixelLeft = newX - 50
        menu.style.pixelTop = newY - 50
    }
    </script>
</body>
</html>