jQuery click function vs inline onclick

前端 未结 5 1837
广开言路
广开言路 2021-02-08 11:28

I\'m trying to reorganize my code and make it more unobstrusive.

Mainly, there is a link for performing an action. If you click on the link, the action is performed via

5条回答
  •  情书的邮戳
    2021-02-08 12:14

    Just demonstrating the use of .end() for a more fluid solution:

    $(function() {          
        $(".add2").click(function(){
                return $(this).parents(".place")
                    .find(".add2")
                        .hide()
                    .end()
                    .find(".actions")
                        .append("Added! Undo");
        });
        $('.undoadd2').live('click', function(){ 
                return $(this).parents(".place")
                    .find(".actions")
                        .find("span.added, a.undoadd2")
                            .remove()
                        .end()
                    .end()
                    .find(".add2")
                        .show();
        });
    });
    

提交回复
热议问题