题解 | #切换Tab栏目#

切换Tab栏目

https://www.nowcoder.com/practice/70916dc9292e470eb70ac2a0d3b9a404

options.onclick = function ({target:{dataset:{type}}}) {
        // 结构出自定义属性data-type,type为字符串
        optionItems.forEach((item, index) => {
          if (index === +type) {
            // 遍历出的option的data-type和index一致则改变背景色,反之设置白色
            // 同时把对应索引下的item显示页面,反之隐藏
            item.style.backgroundColor = "#25bb9b";
            items[index].style.display = "block";
          } else {
            item.style.backgroundColor = "#fff";
            items[index].style.display = "none";
          }
        });
      };

全部评论

相关推荐

投递中移(苏州)软件技术有限公司等公司6个岗位 > 牛客解忧铺
点赞 评论 收藏
转发
2 收藏 评论
分享
牛客网
牛客企业服务