想给test设置多个事件,默认是onclick,如果传参,可以传事件类型,eventType,比如onmouseover,等等,怎么实现,搞了很久还没搞好,麻烦大家帮忙解答一下,谢谢啊
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="test">
a
</div>
<script>
var a = 0;
var test = document.getElementById("test");
var eventType = onmouseover || onclick;
test.onclick = function () {
a++;
console.log(a);
a % 2 == 0 ? test.innerHTML = "a" : test.innerHTML = "b";
}
</script>
</body>
</html>
POPMUISE
相关分类