【问题标题】:jquery selectors - select first three letters of classjquery 选择器 - 选择类的前三个字母
【发布时间】:2012-09-10 15:55:54
【问题描述】:

我的课程前 3 个字母相同

jobOne 工作二 工作三

例如:

<div class="jobOne"></div>
<div class="jobTwo"></div>
<div class="jobThree"></div>

我想匹配所有以 job 开头的类。在一个 div 上。

如何做到这一点?

【问题讨论】:

    标签: jquery class jquery-selectors find


    【解决方案1】:

    您可以使用以下内容,将 div 替换为您选择的元素:

    $("div[class^='job']");
    

    另见官方文档:attribute starts with selector

    【讨论】:

      【解决方案2】:

      查看这个 Jquery 文档:http://api.jquery.com/attribute-starts-with-selector/

      jQuery('[class^="job"]')
      

      【讨论】:

        【解决方案3】:

        你可以使用jQuery属性选择器http://api.jquery.com/attribute-starts-with-selector/

        $("div[class^='job']");
        

        你也可以循环扔掉所有的比赛

        $("div[class^='job']").each(function(){
           // do your coding using $(this)
        });
        

        【讨论】:

          【解决方案4】:

          试试这个

          'HTML 代码'

            <div class="jobOne"></div>
            <div class="jobTwo"></div>
            <div class="jobThrees"></div>
          

          'JS 代码'

          $(document).ready(function(){
              console.log($('div[class^="job"]'));
          });
          

          Have more idea from here

          【讨论】:

          • @welovedesign 有效吗?如需修改请告知。
          猜你喜欢
          • 1970-01-01
          • 2014-05-15
          • 1970-01-01
          • 1970-01-01
          • 2013-03-01
          • 2015-02-26
          • 1970-01-01
          • 1970-01-01
          • 2013-07-10
          相关资源
          最近更新 更多