如何修改此jQuery以将活动类添加到所选链接?

时间:2016-07-21 14:10:18

标签: javascript jquery

jQuery(document).ready(function() {
    jQuery(".page-contents div").hide();
          // Show chosen div, and hide all others
        jQuery("a").click(function (e) {
            //e.preventDefault();
            jQuery("#" + jQuery(this).attr("class")).show().siblings('div').hide();
        });
   });

http://jsfiddle.net/fXE9p/

有人可以解释我如何修改此代码,以便它为所选链接添加“活动”类,以及它是如何工作的?非常感谢您提前

1 个答案:

答案 0 :(得分:0)

以下代码将active类添加到点击链接:

jQuery(document).ready(function() {
    jQuery(".page-contents div").hide();
    // Show chosen div, and hide all others
    jQuery("a").click(function (e) {
        //e.preventDefault();
        //jQuery("#" + jQuery(this).attr("class")).show().siblings('div').hide();
      jQuery(this).addClass("active");
    });
});
相关问题