隐藏(不显示)行||中的空元素在每个循环中显示(显示行内块)不为空的元素

时间:2019-06-02 02:27:06

标签: jquery

我需要在行||中隐藏(不显示)空元素。在每个循环中显示(显示行内块)不为空的元素

我尝试了以下方法:

    if ($('#table-ordersdetail > tbody > tr > td.desserttextmessage > input[type=hidden]').attr('value') !== undefined) {
        $(this).closest('tr').find('td.desserttextmessage').css('display','inline-block');
    } else {
        $(this).closest('tr').find('td.desserttextmessage').css('display','none');
    }

在我的以下jquery脚本中:

JQUERY

$('#table-ordersdetail > tbody > tr > td.producttype_ID input[value=1]').each(function() {

    $(this).closest('tr').find('td.producttype_ID').css('width','10%');
    $(this).closest('tr').find('td.productname').css('width','10%');
    $(this).closest('tr').find('td.dessertservingID').css('display','inline-block');

    if ($('#table-ordersdetail > tbody > tr > td.desserttextmessage > input[type=hidden]').attr('value') !== undefined) {
        $(this).closest('tr').find('td.desserttextmessage').css('display','inline-block');
    } else {
        $(this).closest('tr').find('td.desserttextmessage').css('display','none');
    }

    $(this).closest('tr').find('td.dessertdecorflowerID').css('display','inline-block');
    $(this).closest('tr').find('td.dessertdecorchocolateID').css('display','inline-block');
    $(this).closest('tr').find('td.piedecoration').css('display','none');
    $(this).closest('tr').find('td.ID_portion').css('display','none');
    $(this).closest('tr').find('td.partyloafweightID').css('display','none');
    $(this).closest('tr').find('td.partyloafsandwich1ID').css('display','none');
    $(this).closest('tr').find('td.partyloafsandwich2ID').css('display','none');
    $(this).closest('tr').find('td.partyloafsandwich3ID').css('display','none');
    $(this).closest('tr').find('td.partyloafsandwich4ID').css('display','none');
    $(this).closest('tr').find('td.partyloafribbonID').css('display','none');
    $(this).closest('tr').find('td.slicescutID').css('display','none');
    $(this).closest('tr').find('td.bread_quantity').css('display','none');
    $(this).closest('tr').find('td.canapeID').css('display','none');
    $(this).closest('tr').find('td.minipuffID').css('display','none');
    $(this).closest('tr').find('td.minivolsauventID').css('display','none');
    $(this).closest('tr').find('td.littleappetiserID').css('display','none');
    $(this).closest('tr').find('td.savoury_quantity').css('display','none');
    $(this).closest('tr').find('td.sweetID').css('display','none');
    $(this).closest('tr').find('td.sweet_quantity').css('display','none');
    $(this).closest('tr').find('td.productprice').css('display','none');
    $(this).closest('tr').find('td.productaddfee').css('display','none');
    $(this).closest('tr').find('td.piedecorationprice').css('display','none');
    $(this).closest('tr').find('td.subtotal').css('display','inline-block');
    // $(this).closest('tr').find('td:subtotal').css('width','10%');
    $(this).closest('tr').find('td.subtotal').css('float','right');
    // $(this).closest('tr').find('td:last').css('width','10%');

})

这是桌子:

HTML

<table id="table-ordersdetail" class="table table-striped table-bordered">
<thead>
    <tr>
        <th>ID Client</th>
        <th>ID Rôle</th>
        <th>Statut Ordre</th>
        <th>Statut Labo</th>
        <th>Catégorie</th>
        <th>Produit</th>
        <th># Personnes</th>
        <th>Inscription</th>
        <th>Décoration petites fleurs</th>
        <th>Décoration Chocolat et fruits</th>
        <th>Décoration</th>
        <th>Nombre de sandwiches</th>
        <th>Poids</th>
        <th>Sandwiches 1</th>
        <th>Sandwiches 2</th>
        <th>Sandwiches 3</th>
        <th>Sandwiches 4</th>
        <th>Couleur Ruban</th>
        <th>Coupe du pain</th>
        <th>Quantité</th>
        <th>Variante(s)</th>
        <th>Variante(s)</th>
        <th>Variante(s)</th>
        <th>Variante(s)</th>
        <th>Quantité</th>
        <th>Variante(s)</th>
        <th>Quantité</th>
        <th>Prix</th>
        <th>Supplément</th>
        <th>Supplément décoration</th>
        <th>Total</th>
        <th width="90px">Action</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td class="userID">3
            <input type="hidden" name="ordersdetail-userID[]" value="3">
        </td>
        <td class="roleID">3
            <input type="hidden" name="ordersdetail-roleID[]" value="3">
        </td>
        <td class="statusorderID">2
            <input type="hidden" name="ordersdetail-statusorderID[]" value="2"></td>
        <td class="statuslaboID">1
            <input type="hidden" name="ordersdetail-statuslaboID[]" value="1">
        </td>
        <td class="producttype_ID" style="width: 10%;">Gâteaux
            <input type="hidden" name="ordersdetail-producttype_ID[]" value="1">
        </td>
        <td class="productname" style="width: 10%;">Chocolat
            <input type="hidden" name="ordersdetail-productname[]" value="1">
        </td>
        <td class="dessertservingID" style="display: inline-block;">2-3 pers.
            <input type="hidden" name="ordersdetail-dessertservingID[]" value="1">
        </td>
        <td class="desserttextmessage" style="display: inline-block;">Inscription Inscription Inscription
            <input type="hidden" name="ordersdetail-desserttextmessage[]" value="Inscription Inscription Inscription">
        </td>
        <td class="dessertdecorflowerID" style="display: inline-block;">
            <span class="td-label">Décoration petites fleurs souhaitée</span>
            <input type="hidden" name="ordersdetail-dessertdecorflowerID[]" value="Décoration petites fleurs souhaitée">
        </td>
        <td class="dessertdecorchocolateID" style="display: inline-block;">
            <span class="td-label">Décoration chocolat et fruits souhaitée</span>
            <input type="hidden" name="ordersdetail-dessertdecorchocolateID[]" value="Décoration chocolat et fruits souhaitée">
        </td>
        <td class="piedecoration" style="display: none;">
            <input type="hidden" name="ordersdetail-piedecoration[]" value="">
        </td>
        <td class="ID_portion" style="display: none;">** Veuillez saisir une option Nombre de sandwiches
            <input type="hidden" name="ordersdetail-ID_portion[]" value="">
        </td>
        <td class="partyloafweightID" style="display: none;">
            <input type="hidden" name="ordersdetail-partyloafweightID[]" value="">
        </td>
        <td class="partyloafsandwich1ID" style="display: none;">
            <input type="hidden" name="ordersdetail-partyloafsandwich1ID[]" value="">
        </td>
        <td class="partyloafsandwich2ID" style="display: none;">
            <input type="hidden" name="ordersdetail-partyloafsandwich2ID[]" value="">
        </td>
        <td class="partyloafsandwich3ID" style="display: none;">
            <input type="hidden" name="ordersdetail-partyloafsandwich3ID[]" value="">
        </td>
        <td class="partyloafsandwich4ID" style="display: none;">
            <input type="hidden" name="ordersdetail-partyloafsandwich4ID[]" value="">
        </td>
        <td class="partyloafribbonID" style="display: none;">
            <input type="hidden" name="ordersdetail-partyloafribbonID[]" value="">
        </td>
        <td class="slicescutID" style="display: none;">
            <span class="td-label">Pas de coupe</span>
            <input type="hidden" name="ordersdetail-slicescutID[]" value="Pas de coupe">
        </td>
        <td class="bread_quantity" style="display: none;">
            <input type="hidden" name="ordersdetail-bread_quantity[]" value="">
        </td>
        <td class="canapeID" style="display: none;">
            <input type="hidden" name="ordersdetail-canapeID[]" value="">
        </td>
        <td class="minipuffID" style="display: none;">
            <input type="hidden" name="ordersdetail-minipuffID[]" value="">
        </td>
        <td class="minivolsauventID" style="display: none;">
            <input type="hidden" name="ordersdetail-minivolsauventID[]" value="">
        </td>
        <td class="littleappetiserID" style="display: none;">
            <input type="hidden" name="ordersdetail-littleappetiserID[]" value="">
        </td>
        <td class="savoury_quantity" style="display: none;">
            <input type="hidden" name="ordersdetail-savoury_quantity[]" value="">
        </td>
        <td class="sweetID" style="display: none;">
            <input type="hidden" name="ordersdetail-sweetID[]" value="">
        </td>
        <td class="sweet_quantity" style="display: none;">
            <input type="hidden" name="ordersdetail-sweet_quantity[]" value="">
        </td>
        <td class="productprice" style="display: none;">19.00
            <input type="hidden" name="ordersdetail-productprice[]" value="19.00">
        </td>
        <td class="productaddfee" style="display: none;">5.00
            <input type="hidden" name="ordersdetail-productaddfee[]" value="5.00">
        </td>
        <td class="piedecorationprice" style="display: none;">0.00
            <input type="hidden" name="ordersdetail-piedecorationprice[]" value="0.00">
        </td>
        <td class="subtotal" style="display: inline-block; float: right;">24.00
            <input type="hidden" name="ordersdetail-subtotal[]" value="24.00">
        </td>
        <td>
            <a href="#panel-form-ordersdetail" onclick="editRowordersdetail(this)" class="btn btn-warning btn-xs"><i class="fa fa-pencil"></i></a>
            <a href="javascript:void(0)" onclick="deleteRowordersdetail(this)" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i></a>
        </td>
    </tr>
    <tr>
        <td class="userID">3
            <input type="hidden" name="ordersdetail-userID[]" value="3">
        </td>
        <td class="roleID">3
            <input type="hidden" name="ordersdetail-roleID[]" value="3">
        </td>
        <td class="statusorderID">2
            <input type="hidden" name="ordersdetail-statusorderID[]" value="2">
        </td>
        <td class="statuslaboID">1
            <input type="hidden" name="ordersdetail-statuslaboID[]" value="1">
        </td>
        <td class="producttype_ID" style="width: 10%;">Gâteaux
            <input type="hidden" name="ordersdetail-producttype_ID[]" value="1">
        </td>
        <td class="productname" style="width: 10%;">Chocolat
            <input type="hidden" name="ordersdetail-productname[]" value="1">
        </td>
        <td class="dessertservingID" style="display: inline-block;">2-3 pers.
            <input type="hidden" name="ordersdetail-dessertservingID[]" value="1">
        </td>
        <td class="desserttextmessage" style="display: inline-block;">
            <input type="hidden" name="ordersdetail-desserttextmessage[]" value="">
        </td>
        <td class="dessertdecorflowerID" style="display: inline-block;">
            <span class="td-label">Décoration petites fleurs souhaitée</span>
            <input type="hidden" name="ordersdetail-dessertdecorflowerID[]" value="Décoration petites fleurs souhaitée">
        </td>
        <td class="dessertdecorchocolateID" style="display: inline-block;">
            <span class="td-label">Décoration chocolat et fruits souhaitée</span>
            <input type="hidden" name="ordersdetail-dessertdecorchocolateID[]" value="Décoration chocolat et fruits souhaitée">
        </td>
        <td class="piedecoration" style="display: none;">
            <input type="hidden" name="ordersdetail-piedecoration[]" value="">
        </td>
        <td class="ID_portion" style="display: none;">** Veuillez saisir une option Nombre de sandwiches
            <input type="hidden" name="ordersdetail-ID_portion[]" value="">
        </td>
        <td class="partyloafweightID" style="display: none;">
            <input type="hidden" name="ordersdetail-partyloafweightID[]" value="">
        </td>
        <td class="partyloafsandwich1ID" style="display: none;">
            <input type="hidden" name="ordersdetail-partyloafsandwich1ID[]" value="">
        </td>
        <td class="partyloafsandwich2ID" style="display: none;">
            <input type="hidden" name="ordersdetail-partyloafsandwich2ID[]" value="">
        </td>
        <td class="partyloafsandwich3ID" style="display: none;">
            <input type="hidden" name="ordersdetail-partyloafsandwich3ID[]" value="">
        </td>
        <td class="partyloafsandwich4ID" style="display: none;">
            <input type="hidden" name="ordersdetail-partyloafsandwich4ID[]" value="">
        </td>
        <td class="partyloafribbonID" style="display: none;">
            <input type="hidden" name="ordersdetail-partyloafribbonID[]" value="">
        </td>
        <td class="slicescutID" style="display: none;">
            <span class="td-label">Pas de coupe</span>
            <input type="hidden" name="ordersdetail-slicescutID[]" value="Pas de coupe">
        </td>
        <td class="bread_quantity" style="display: none;">
            <input type="hidden" name="ordersdetail-bread_quantity[]" value="">
        </td>
        <td class="canapeID" style="display: none;">
            <input type="hidden" name="ordersdetail-canapeID[]" value="">
        </td>
        <td class="minipuffID" style="display: none;">
            <input type="hidden" name="ordersdetail-minipuffID[]" value="">
        </td>
        <td class="minivolsauventID" style="display: none;">
            <input type="hidden" name="ordersdetail-minivolsauventID[]" value="">
        </td>
        <td class="littleappetiserID" style="display: none;">
            <input type="hidden" name="ordersdetail-littleappetiserID[]" value="">
        </td>
        <td class="savoury_quantity" style="display: none;">
            <input type="hidden" name="ordersdetail-savoury_quantity[]" value="">
        </td>
        <td class="sweetID" style="display: none;">
            <input type="hidden" name="ordersdetail-sweetID[]" value="">
        </td>
        <td class="sweet_quantity" style="display: none;">
            <input type="hidden" name="ordersdetail-sweet_quantity[]" value="">
        </td>
        <td class="productprice" style="display: none;">19.00
            <input type="hidden" name="ordersdetail-productprice[]" value="19.00">
        </td>
        <td class="productaddfee" style="display: none;">5.00
            <input type="hidden" name="ordersdetail-productaddfee[]" value="5.00">
        </td>
        <td class="piedecorationprice" style="display: none;">0.00
            <input type="hidden" name="ordersdetail-piedecorationprice[]" value="0.00">
        </td>
        <td class="subtotal" style="display: inline-block; float: right;">24.00
            <input type="hidden" name="ordersdetail-subtotal[]" value="24.00">
        </td>
        <td>
            <a href="#panel-form-ordersdetail" onclick="editRowordersdetail(this)" class="btn btn-warning btn-xs"><i class="fa fa-pencil"></i>
            </a> <a href="javascript:void(0)" onclick="deleteRowordersdetail(this)" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i></a>
        </td>
    </tr>
</tbody>
</table>

仍然显示空的“ desserttextmessage”,如您在所附的屏幕截图中所见。

screenshot

在此感谢您的一些专业知识。谢谢。

0 个答案:

没有答案