Pass javascript function as data-* attribute and execute

前端 未结 4 791
甜味超标
甜味超标 2021-02-11 18:21

We know such syntaxes as below, when defining a value for onClick attribute:

4条回答
  •  再見小時候
    2021-02-11 18:39

    I think a better idea would be to dynamically bind the events and trigger them. If you wanted them to only be known by other code, you could use custom events.

    
    
    
    
    
    
    

    Then your other components could invoke them with $(selector).trigger('customCallback');

提交回复
热议问题