How to change onClick handler dynamically?

前端 未结 11 1602
清歌不尽
清歌不尽 2020-12-02 15:37

I\'m sure there are a million posts about this out there, but surprisingly I\'m having trouble finding something.

I have a simple script where I want to set the onC

11条回答
  •  孤城傲影
    2020-12-02 16:12

    jQuery:

    $('#foo').click(function() { alert('foo'); });
    

    Or if you don't want it to follow the link href:

    $('#foo').click(function() { alert('foo'); return false; });
    

提交回复
热议问题