0

テーブルの列を確認しようとしていますが、列に「NA」値が含まれている場合は、テーブルの行を非表示にする必要があります。

これが私が試したJSコードです。

$("table tr td:nth-child(2)").contains("NA", function (){
   ("table tr").hide(); 
});

テーブルは次のようになります。

Opti_Mi_Learning_Linear_Pro:        2
Opti_Mi_Learning_Quadratic_Pro:     1
Opti_Mi_Learning_Integer_Pro:       na
Opti_Mi_Learn:                      1
Opti_Mi_Learn_Evolu_Algo:           na
Opti_Mi_Lear_Neural_Networks:       na

誰かが私のコードを修正するのを手伝ってくれますか?

4

3 に答える 3

1

1つの方法は、次を使用すること.filter()です:

$("table tr").filter(function () {
  return $.trim( $(this).find("td:nth-child(2)").text() ) === "NA";
}).hide();
于 2013-06-17T06:54:23.167 に答える
1

要素のテキストを取得してから、文字列チェックを使用します。たとえば、次のようになります。

if ($("table tr td:nth-child(2)").text().indexOf("NA") !== -1) {
     // ...it contains NA, possibly with text before and/or after...
}

また

if ($("table tr td:nth-child(2)").text() === "NA") {
     // ...it's *exactly* the text "NA" ...
}

上記のチェックはどちらも大文字と小文字が区別されます。大文字と小文字を区別しないようにするには、.toUpperCase()単に.text().

于 2013-06-17T06:50:05.907 に答える