button 事件屬性可返回一個整數(shù),指示當事件被觸發(fā)時哪個鼠標按鍵被點擊。
event.button=0|1|2
參數(shù) | 描述 |
---|---|
0 | 規(guī)定鼠標左鍵。 |
1 | 規(guī)定鼠標中鍵。 |
2 | 規(guī)定鼠標右鍵。 |
Internet Explorer 擁有不同的參數(shù):
參數(shù) | 描述 |
---|---|
1 | 規(guī)定鼠標左鍵。 |
4 | 規(guī)定鼠標中鍵。 |
2 | 規(guī)定鼠標右鍵。 |
注釋:對于慣用左手的鼠標配置,上面的參數(shù)是顛倒的。
提示:Mozilla 的 Ctrl–Click 參數(shù)是 2 (等價于右擊)。
The following example alerts which mouse button was clicked:
<html>
<head>
<script type="text/javascript">
function whichButton(event)
{
if (event.button==2
)
{
alert("You clicked the right mouse button!")
}
else
{
alert("You clicked the left mouse button!")
}
}
</script>
</head>
<body onmousedown="whichButton(event)">
<p>Click in the document. An alert box will
alert which mouse button you clicked.</p>
</body>
</html>
如對本文有疑問,請?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會為你解答?。?點擊進入論壇
Powered by 365建站網(wǎng) RSS地圖 HTML地圖
copyright © 2013-2024 版權所有 鄂ICP備17013400號