Duplicate one element's event handlers onto another?

前端 未结 6 1568
半阙折子戏
半阙折子戏 2021-02-14 01:51

How do you copy an event handler from one element to another? For example:

$(\'#firstEl\')
    .click(function() {
        alert(\"Handled!\");
         


        
6条回答
  •  一个人的身影
    2021-02-14 02:23

    $('#secondEl').click = $('#firstEl').click.bind($('#secondEl'));

    Assuming you are using Prototype JS (http://www.prototypejs.org/api/function/bind)

提交回复
热议问题