为同一元素绑定多个不同事件,指向同一事件处理函数

91 阅读1分钟
    document.onclick = f1;
    document.onmouseover = f1;
    document.onmouseout = f1;
    function f1(e) {
        switch (e.type) {
            case "click": alert("你好啊!");
                break;
            case "mouseover": this.style.backgroundColor = "red";
                break;
            case "mouseoiut": this.style.backgroundColor = "green";
                break;
            default:
                break;
        }
    }