大佬教程收集整理的这篇文章主要介绍了jquery – .addClass()其中data-id等于data-category?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在这里,我只是.addClass到所有.item类,我不知道如何编写它,以便它将类添加到匹配data-id的数据类.
未完成的jQuery代码段:
$(".breadcrumb-cell .breadcrumb").click(function () { var thEID = $(this).data("id"),theCAT = $('.item').attr("data-category"),item = $('.item') //This just shows you that when you click the element it returns the data-id each click alert(thEID); // Here I gave it a few shots but no success,so I just add .active to all item.addClass('active'); });
这感觉有点蠢,但我没有搞砸这种写作(匹配数据属性)所以一点点知识将是惊人的.
答案::Sushanth –
$(".breadcrumb-cell .breadcrumb").click(function () { var thEID = $(this).data("id"),$allItem = $('.item'),$currItem = $('.item[data-category=' + thEID + ']') $currItem.addClass('active'); $allItem.not($currItem).removeClass('active'); });
以上是大佬教程为你收集整理的jquery – .addClass()其中data-id等于data-category?全部内容,希望文章能够帮你解决jquery – .addClass()其中data-id等于data-category?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。