【问题标题】:Load different jQuery code by href?通过href加载不同的jQuery代码?
【发布时间】:2013-03-10 16:50:17
【问题描述】:

我有一个类似的菜单:

<a href="http://www.something.it/project/">TYPE 1</a>
<a href="http://www.something.it/project/">TYPE 2</a>
...

我需要在加载项目页面时加载这个 jQuery:

$('ul#filters li').each(function() {
    if(!$(this).hasClass('TYPE N')) {
    $(this).fadeOut('normal').addClass('hidden');
} else {
    $(this).fadeIn('slow').removeClass('hidden');
    }});

href 必须通过 TYPE。如果我点击“Type 1”的链接,在项目页面加载后我需要加载:

$('ul#filters li').each(function() {
    if(!$(this).hasClass('Type 1')) {
    $(this).fadeOut('normal').addClass('hidden');
} else {
    $(this).fadeIn('slow').removeClass('hidden');
    }});

我该怎么做?

谢谢,

【问题讨论】:

    标签: jquery parameter-passing href


    【解决方案1】:

    替换您的以下行:

    if(!$(this).hasClass('TYPE 1')) {
    

    对于这个:

    if( $(this).find('a').text() != 'TYPE 1') {
    

    &lt;a&gt; 元素的文本内容相比,这应该可以满足您的需求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-21
      相关资源
      最近更新 更多