【问题标题】:Target specific href with jQuery [closed]使用 jQuery 定位特定的 href [关闭]
【发布时间】:2013-05-31 11:41:07
【问题描述】:

我正在使用此代码在一个页面上打开多个链接, http://fiddle.jshell.net/njA8z/1/

但是—— 1. 我希望代码仅针对具有类链接的 div 中的 href ---
2. 我需要在另一个页面上重复使用相同的代码,但要针对所有具有类链接的链接。

<a href="#!mylink" class="links">Link</a>

感谢任何帮助。

【问题讨论】:

    标签: jquery click href


    【解决方案1】:

    你可以这样做:

    $("div a.links[href]");
    

    【讨论】:

      【解决方案2】:

      你可以试试

      $('#ButtonOne').click(function() {
          $('div a.links').each(function() {
              window.open($(this).attr('href'););
          });
      });
      

      【讨论】:

        【解决方案3】:

        您可以尝试使用 jQuery 的.hasClass() 方法。

        这样的东西应该可以工作

        if($('div').hasClass('links')){
            // do what you need to with the links in here
        }
        

        【讨论】:

        • 谢谢。这看起来很不错。
        猜你喜欢
        • 2021-08-24
        • 2012-09-23
        • 2020-03-29
        • 2011-08-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-11
        相关资源
        最近更新 更多