Jquery检查tr是否没有带有类的项目并删除重复项

时间:2013-02-01 23:18:49

标签: javascript jquery

我有这样的html表:

<div class="1233">hello</div>
<table cellpadding="0" cellspasing="0" class="sortable zebra tablesorter tablesorter-default"
id="articles-table">
    <thead>
        <tr class="tablesorter-headerRow">
            <th data-column="0" class="tablesorter-header">
                <div class="tablesorter-header-inner">Производитель<i class="tablesorter-icon"></i>
                </div>
            </th>
            <th data-column="1" class="tablesorter-header">
                <div class="tablesorter-header-inner">Артикул<i class="tablesorter-icon"></i>
                </div>
            </th>
            <th data-column="2" class="tablesorter-header">
                <div class="tablesorter-header-inner">Описание<i class="tablesorter-icon"></i>
                </div>
            </th>
            <th data-column="3" class="tablesorter-header">
                <div class="tablesorter-header-inner"><i class="tablesorter-icon"></i>
                </div>
            </th>
            <th class="prcol  tablesorter-header tablesorter-headerSortDown" data-column="4">
                <div class="tablesorter-header-inner">Цена<i class="tablesorter-icon"></i>
                </div>
            </th>
            <th data-column="5" class="tablesorter-header">
                <div class="tablesorter-header-inner">Наличие<i class="tablesorter-icon"></i>
                </div>
            </th>
            <th data-column="6" class="tablesorter-header">
                <div class="tablesorter-header-inner">Сроки поставки<i class="tablesorter-icon"></i>
                </div>
            </th>
            <th data-column="7" class="tablesorter-header">
                <div class="tablesorter-header-inner"><i class="tablesorter-icon"></i>
                </div>
            </th>
        </tr>
    </thead>
    <tbody class="analogs_art">
        <tr class="zebra-stripe zebra-grey zebra2 even">
            <td>
                 <h5>Knecht</h5>
            </td>
            <td>
                 <h4>OC90</h4>
            </td>
            <td style="max-width: 300px;">(07786171)Фильтр масл OPEL (07786171)Фильтр масл OPEL</td>
            <td></td>
            <td>6124</td>
            <td>20</td>
            <td>0-1</td>
            <td id="to_cart_and_qnt_td">
                <form accept-charset="UTF-8" action="/line_items" method="post">
                    <div style="margin:0;padding:0;display:inline">
                        <input name="utf8" type="hidden" value="✓">
                        <input name="authenticity_token" type="hidden" value="0jlRLSkDKi6eM5SSL+3uRB0w2G141KUcJKuy4Bg2YNo=">
                    </div>
                    <input id="ART" name="ART" type="hidden" value="y1M1ZtdXgnMe6pOjjuXWPqhYR41SmQRKzlDOQ1uPwuru+AamPGpcOwOFFylbRDu5M1XUawCnukqNDQCuIr0JPA==--vNGx6/lYKRrpD5NGTJALcQ==">
                    <input id="price" name="price" type="hidden" value="TodzvfOZCbK5T9+RLE1IQg==--qq8o30c5rTX91F8W42wdsQ==">
                    <input id="distributor_id" name="distributor_id" type="hidden" value="6">
                    <input id="waittime" name="waittime" type="hidden" value="1">
                    <input class="qnt_to_cart2" id="OC90" name="cart_quantity" pattern="0|[1-9]\d{0,2}"
                    required="required" type="text" value="1">
                    <input class="orange-button to-cart_no" id="OC90" name="commit" type="submit"
                    value="В корзину">
                </form>
            </td>
        </tr>
        <tr class="zebra-stripe zebra-grey zebra2 odd">
            <td>
                 <h5>KNECHT</h5>
            </td>
            <td>
                 <h4>OC 90</h4>
            </td>
            <td style="max-width: 300px;">Масляный фильтр</td>
            <td> <a href="/articles/1248525/details" class="details-link">подробнее</a>

                <a
                href="/articles/1248525" class="analogs-link">аналоги</a>
            </td>
            <td>6124</td>
            <td>20</td>
            <td>0-1</td>
            <td id="to_cart_and_qnt_td">
                <form accept-charset="UTF-8" action="/line_items" method="post">
                    <div style="margin:0;padding:0;display:inline">
                        <input name="utf8" type="hidden" value="✓">
                        <input name="authenticity_token" type="hidden" value="0jlRLSkDKi6eM5SSL+3uRB0w2G141KUcJKuy4Bg2YNo=">
                    </div>
                    <input id="ART" name="ART" type="hidden" value="9x6mdLbW2aMaHqFK32kZwHWnWA7n0GBp/jXS8KeECsTS+78ytG0SQzFpVODplws5iHm6B6SkZzi3ej2+zpW8iQ==--RNoUUgcZu7MLU8BHJ4ynSQ==">
                    <input id="price" name="price" type="hidden" value="VqatEYzkPEf3P9Y/jNY9Zg==--Iw5nQDqjK9vvZX/RecD1eA==">
                    <input id="distributor_id" name="distributor_id" type="hidden" value="6">
                    <input id="waittime" name="waittime" type="hidden" value="1">
                    <input class="qnt_to_cart" id="cart_quantity" name="cart_quantity" pattern="0|[1-9]\d{0,2}"
                    required="required" type="text" value="1">
                    <input class="orange-button to-cart" name="commit" type="submit" value="В корзину">
                </form>
            </td>
        </tr>
        <tr class="zebra-stripe zebra-grey zebra1 even">
            <td>
                 <h5>Knecht</h5>
            </td>
            <td>
                <h4>OC90</h4>
            </td>
            <td style="max-width: 300px;">Фильтр масляный OPEL/GM/DAEWOO Фильтр масляный OPEL/GM/DAEWOO</td>
            <td></td>
            <td>6142</td>
            <td>1000</td>
            <td>3</td>
            <td id="to_cart_and_qnt_td">
                <form accept-charset="UTF-8" action="/line_items" method="post">
                    <div style="margin:0;padding:0;display:inline">
                        <input name="utf8" type="hidden" value="✓">
                        <input name="authenticity_token" type="hidden" value="0jlRLSkDKi6eM5SSL+3uRB0w2G141KUcJKuy4Bg2YNo=">
                    </div>
                    <input id="ART" name="ART" type="hidden" value="NqgWSvcdv0FEQkjcJZp98gIYe20Fjol8Bn31tB/CjWnTFVsa3J3hmldO1RSqS/pNUcVZ5dh0wcP7YeZxPAkQc4DEPKy7EVuTpMw3oQw58T0=--/XCn0hP3w0mglJ1vTXSjHw==">
                    <input id="price" name="price" type="hidden" value="mFPLSHh7AdEMpQJiZHFKNg==--hfJQGWhjBoD6mNAetXZ3Xw==">
                    <input id="distributor_id" name="distributor_id" type="hidden" value="6">
                    <input id="waittime" name="waittime" type="hidden" value="3">
                    <input class="qnt_to_cart2" id="OC90" name="cart_quantity" pattern="0|[1-9]\d{0,2}"
                    required="required" type="text" value="1">
                    <input class="orange-button to-cart_no" id="OC90" name="commit" type="submit"
                    value="В корзину">
                </form>
            </td>
        </tr>
    </tbody>
</table>

如何在我的jscript中:

if(tr.not('.details-link')){

我可以单独留下这样的td,我没有class = details-link? 现在我的代码无效......

只是跳过编辑我的代码,这样如果tr没有课程,我会做点什么......怎么做?

UPD 我需要这样做: 的 http://jsfiddle.net/zvKSc/8/

删除重复项(1,2,5列通过小写和删除空格必须相等...),但留在页面上这样的tr,其中一个td我有类详细信息 - 链接...所以在小提琴从三个我必须先删除,并留下第二和第三tr

1 个答案:

答案 0 :(得分:1)

if(!$('tr').hasClass('details-link')) {

// code to execute if tr does not have class

}

查看hasClass方法:http://api.jquery.com/hasClass/