最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

怎么用js給document添加一個鼠標單擊事件?

怎么用js給document添加一個鼠標單擊事件?

千萬里不及你 2019-04-08 15:11:45
怎么用js給document添加一個鼠標單擊事件
查看完整描述

3 回答

?
阿晨1998

TA貢獻2037條經(jīng)驗 獲得超6個贊

JS獲取點擊事件來自左鍵還是其它鍵的方法如下:

返回值說明:0左鍵,1中間,2右鍵

getButton:function(event){

if (document.implementation.hasFeature("MouseEvents","2.0")){

return event.button;

}else{

switch(event.button){

case 0:

case 1:

case 3:

case 5:

case 7:

return 0;

case 2:

case 6:

return 2;

case 4:

return 1;

}

}

}



查看完整回答
反對 回復 2019-04-10
?
天涯盡頭無女友

TA貢獻1831條經(jīng)驗 獲得超9個贊

<script type="text/javascript">
//如果畫面有很多 a Tag 的時候
var lin = document.getElementsByTagName("a");
for(var i=0; i<lin.length;i++){
lin[i].onclick = function(){

// 想寫的事件內(nèi)容
}
}
//按鈕點擊事件
var button = document.getElementById("XXX");
button.onclick = function(){
// 想寫的事件內(nèi)容
}

</script>


查看完整回答
反對 回復 2019-04-10
?
翻閱古今

TA貢獻1780條經(jīng)驗 獲得超5個贊

 

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

<!DOCTYPE html>

<html>

<head lang="en">

    <meta charset="UTF-8">

    <title></title>

    <script type="text/javascript">

       window.onload = function(){

           //去掉默認的contextmenu事件,否則會和右鍵事件同時出現(xiàn)。

           document.oncontextmenu = function(e){

               e.preventDefault();

           };

           document.getElementById("test").onmousedown = function(e){

               if(e.button ==2){

                   alert("你點了右鍵");

               }else if(e.button ==0){

                   alert("你點了左鍵");

               }else if(e.button ==1){

                   alert("你點了滾輪");

               }

           }

       }

    </script>

</head>

<body>

 

<div style="width: 400px;height:400px;margin:auto;border:1px solid pink" id="test"></div>

</body>

</html>


查看完整回答
反對 回復 2019-04-10
  • 3 回答
  • 0 關(guān)注
  • 2954 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號