JavaScript Reference/Javascript Properties/button

Материал из Web эксперт
Перейти к: навигация, поиск

"button" Example

    
<html>
<body>
<script language="JavaScript">
    function function1() {
        var m = window.event.button;
        if (m == 1) { 
            alert("The left button has been pressed"); 
        } else if (m == 2) { 
            alert("The right button has been pressed"); 
        }
    }
</script>
<div style="width:200; 
            height:200; 
            background-color:blue;" 
     onmousedown="function1();">
Press on mouse while on top of this blue box.
</div>
</body>
</html>



"button" is applied to

+----------------+--------------------------------------------------------------+
| Applied_To     |event                                                         |
+----------------+--------------------------------------------------------------+



"button" Possible Values

Possible Values
0              the default; no button is pressed,
1              left button is pressed,
2              right button is pressed,
3              left and right buttons are pressed,
4              middle button is pressed,
5              left and middle buttons are pressed,
6              right and middle buttons are pressed,
7              all three buttons are pressed.



"button" Syntax and Note

Note:
Read and write property. 
Specifies the mouse button pressed by the user. 
    
Syntax:
    
window.event.button = value