Pass javascript function as data-* attribute and execute

前端 未结 5 673
陌清茗
陌清茗 2021-02-11 18:31

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

5条回答
  •  不知归路
    2021-02-11 18:35

    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');

提交回复
热议问题