js简单封装能向回调函数传入参数的事件处理函数

<!doctype html>html

<html>dom

<head>htm

    <meta charset="UTF-8">ip

    <title>Document</title>get

</head>input

<body>it

<input type="text" id="fInp"/>io

<script>console

    var eventRegister = function(dom, type, data, callBack){event

        var callback = function(e){

            callBack(e,data);

        }

        if(window.addEventListener){

            dom.addEventListener(type, callback, false);

        }else if(window.attachEvent){

            dom.attachEvent('on'+type, callback);

        }

    };

    function handler(e,data){

        console.log(e);

        console.log(data);

    }

    eventRegister(document.getElementById('fInp'), 'click', {name:'kk'}, handler);

</script>

</body>

</html>

相关文章
相关标签/搜索