简体   繁体   English

jQuery的。选择具有类但没有style =“display:none;”属性的所有元素

[英]jQuery. Select all elements with a class but without style=“display:none;” attribute

I have the following class, which selects what's inside of the td.lineitemtotal cells and uses it in the getTotal function to get a total of the cells. 我有以下类,它选择td.lineitemtotal单元格中的内容并在getTotal函数中使用它来获取总数的单元格。 But, I don't want the function to use the lines that are in a tr.line_item_row with style="display:none;" 但是,我不希望函数使用样式=“display:none;”的tr.line_item_row中的行。 attribute. 属性。

$(document).ready(function() {
  var line = $('.item');
  // so the line totals are calculated on page load
  getLineItemTotals(line);

  var line_totals = $('.lineitemtotal');
  getTotal(line_totals); // So the total is calculated on page load.
});

// get invoce grand total
function getTotal(lines) {
  var total = 0;
  $.each(lines, function(){
    total += parseFloat($(this).html());
  });
  $('#total-price').html('$' + total.toFixed(2));
}

Do you want this ? 你想要这个吗 ?

$('.lineitemtotal:visible');

This set contains the not hidden elements having class lineitemtotal . 此集包含具有class lineitemtotal类的非隐藏元素。

var line_totals = $('.lineitemtotal:not([style*="display:none"])');

在您的选择器上包括:visible选择器:

$('.lineitemtotal:visible');

If you know for certain that the attribute will always be style="display:none;" 如果您确定该属性将始终为style="display:none;" you can use an attribute selector. 您可以使用属性选择器。

Instead of this: 而不是这个:

var line = $('.item');

Try this: 试试这个:

var line = $('.item[style!="display:none;"]');

using [attribute="value"] looks for elements that have attribute with value value , adding the ! 使用[attribute="value"]查找具有值value attribute元素,添加! before the = looks for things that do NOT match. =之前寻找不匹配的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM