0

このサイトで、行内のセル内で値を直接読み取ることに基づいて行を非表示にする JavaScript の例を見つけましたが、テキスト入力フィールド内の値を読み取るために必要です。

私が使用しているJavaScriptは次のとおりです。

function hide() {
var tbl = document.getElementById('Table'),
    rows = tbl.tBodies[0].children, l = rows.length, i,
    filter = function(cells) { 
        var values = [
            parseInt(cells[0].firstChild.nodeValue.replace(/,/g,''),10),
            parseFloat(cells[1].firstChild.nodeValue.replace(/,/g,''))
        ];
        if( values[1] < 1) return false;
        return true;
    };
for( i=0; i<l; i++) {
    if( !filter(rows[i].cells)) rows[i].style.display = "none";
}
}

HTMLは次のとおりです。

 <tr>
<tdRow 1</td>
<td>1<input id="Quantity1" name="Quantity1" class="numericValue" type="text" value="1" /></td>
</tr>
<tr>
<td>Row 2</td>
<td>2<input id="Quantity2" name="Quantity2" class="numericValue" type="text" value="2" /></td>
</tr>
<tr>
<td>Row 3</td>
<td>3<input id="Quantity3" name="Quantity3" class="numericValue" type="text" value="0" /></td>
</tr>
<tr>
<td>Row 4</td>
<td>4<input id="Quantity4" name="Quantity4" class="numericValue" type="text" value="0" /></td>
</tr>
<tr>
<td>Row 5</td>
<td>0<input id="Quantity5" name="Quantity5" class="numericValue" type="text" value="0" /></td>
</tr>

<input id="btnSubmit" onclick="hide();" type="submit" value="Hide" /></p>

そのままではjsは5行目の「0」を読み取って非表示にしますが、入力値が「0」の3,4,5行を非表示にしたいです。入力値を取得するにはどうすればよいですか? これは、入力値がすべて "0" (数量の場合) から始まり、1 つまたは複数の値が変更されるテーブル用です。

ありがとう。

4

1 に答える 1