get the value of “onclick” with jQuery?

前端 未结 6 657
耶瑟儿~
耶瑟儿~ 2020-12-09 15:16

Is it possible to get the current value of the onClick attribute of an A tag via jQuery?

For example, I have:



        
6条回答
  •  春和景丽
    2020-12-09 15:55

    $('#google').attr('onclick') + ""
    

    However, Firebug shows that this returns a function 'onclick'. You can call the function later on using the following approach:

    (new Function ($('#google').attr('onclick') + ';onclick();'))()
    

    ... or use a RegEx to strip the function and get only the statements within it.

提交回复
热议问题