2016-07-21 17 views
-2
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/如何修改此jQuery以将活动类添加到所选链接?

有人能解释我如何去这样它增加了一个“积极”级到选定的链接修改这个代码,以及它是如何工作的?敬请谢谢你在前进

回答

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"); 
    }); 
}); 
相关问题