What's the best way to replace links with JS functions?

后端 未结 8 1713
死守一世寂寞
死守一世寂寞 2021-01-31 05:49

A pattern that\'s started to show up a lot in one of the web apps I\'m working are links that used to just be a regular a-tag link now need a popup box asking \"are you sure?\"

8条回答
  •  礼貌的吻别
    2021-01-31 06:35

    In jquery it is something like:

    $("a").click(function() {if(confirm('yadda yadda')) event.stopPropagation();});
    

    If I understand what jgreep mentioned, if you only want the confirm to appear on a few links, you would bind the click handler only to links with the right class. You could do this only for anchors or for any html element that has the class.

    $(".conf").click(function() {if(confirm('yadda yadda')) event.stopPropagation();});
    

提交回复
热议问题