How to set jQuery this when calling a function?

前端 未结 3 1147
深忆病人
深忆病人 2021-01-04 11:27

Using jQuery, I set a link tag\'s click handler like this:

$(\'#lnk\').click(handleClick);

handleClick does something like this:

         


        
3条回答
  •  醉梦人生
    2021-01-04 12:28

    Use Function.apply and pass in the DOM element returned by the query.

    handleClick.apply($('#lnk')[0]);
    

    Or better yet, let jQuery simulate a click on the element (Assuming you've already attached the click event handler).

    $('#lnk').click();
    

提交回复
热议问题