我是 js 和 jQuery 的新手,我写了一些我认为可以优化的代码。这是我所拥有的:
$(".team-member.personX").click(function(){
$(this).children(".img-mask").attr("src", "images/img-mask-active.png");
$(".member-info.personX").fadeIn();
});
$(".member-info.personX .close").click(function(){
$(".team-member.personX .img-mask").attr("src", "images/img-mask.png");
$(".member-info.personX").fadeOut();
});
主要是我想问有没有一种方法可以用1,2,3,4替换-- X --而不会重复相同的代码 4 次。任何帮助将不胜感激。