Get value of current event handler using jQuery

后端 未结 2 1898
礼貌的吻别
礼貌的吻别 2021-01-18 15:54

I can set the onclick handler using jQuery by calling

$(\'#id\').click(function(){
   console.log(\'click!\');
});

Also using jQuery, how can

2条回答
  •  走了就别回头了
    2021-01-18 16:16

    if you dont know the name of the function you can use

    args.callee

    https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope/arguments/callee

    function clickHandle(e){
      if($(e.target) == $('#id')) {
      $(newTarget).bind('click',  clickHandle);
      }
    }
    
    $('#id').bind('click',clickHandle);
    

    I think this would be the most symantic way of going about it

提交回复
热议问题