0

http://medfor.petersenuploads.co.uk/product.php/698/2/clear-ps-honey-jar-with-metal-screw-cap

当前屏幕中间有一组下拉菜单和一个选项卡(完整产品列表)。如果您单击完整产品列表中的产品之一,它会更新下拉列表。这包括一个隐藏字段(每个案例的项目)

我想要做的是根据 3 个选定的下拉菜单获取每个案例的项目(从表中)的值。例如:

选择 100ml,无菌 R,无标签 - 这与表中的第二行匹配。我想从表中获取“每箱物品”的值,以便我可以设置隐藏的下拉列表(每箱物品)并获取要添加到购物篮的正确产品。

执行此操作的代码在 script.js 中

// Handles changing any drop downs in the product selection area and updates the choosen item based on label names and field values.
$('.product-options select').change(function() {
    $('p.selection-item').text("");
    $('#selection-name').text($('header>h1').text());
    $('.product-options select').each(function (i) {
        $('p.selection-item').append($("label[for='"+$(this).attr("id")+"']").text() + " " + $('option:selected', this).text(), "<br />");

        var tableRow = $(".product-table td").filter(function() {
            return $(this).text() == "50";
            //Needs to match against all drop down values
        }).closest("tr");
        console.log(tableRow);
    });
    $('div.product-selection h2').removeClass('noshow');
    $('div.product-selection p').removeClass('noshow');
    recalcPrice($('#pid').val());
});

我需要过滤表以获取单行,然后获取倒数第二列的值。我怎样才能做到这一点?

4

1 回答 1

1

假设 columns / td 放置是静态的,您可以执行以下操作。

var tableRow = $(".product-table tbody tr").filter(function() {
            var
                cap = $("#capacity :selected").text(),
                ster = $("#sterility :selected").text(),
                lbl = $("#labeltype :selected").text();
            return $(this).find("td").eq(0).text() == cap && $(this).find("td").eq(1).text() == ster && $(this).find("td").eq(2).text() == lbl
        });

如果 columns / td 放置是动态的,您可以执行以下操作。

var tableRow = $(".product-table tbody tr").filter(function() {
            var arr = [],
                cap = $("#capacity :selected").text(),
                ster = $("#sterility :selected").text(),
                lbl = $("#labeltype :selected").text();
            $.each($(this).find("td"), function(){
               arr.push($(this).text());//there was a parenthesis missing here.
            });
            return $.inArray(cap, arr) != -1 && $.inArray(ster, arr) != -1 && $.inArray(lbl, arr) != -1;
        });
于 2012-11-07T17:13:53.630 回答