1

ストーリータイム。

だから、私はこのHTMLコードを持っています:

<tr valign="top" class="">
    <td class="col-status status-yellow">&nbsp;</td>
    <td class="col-chk"><input name="ctl00" type="checkbox" class="checklistitem" title="Not Applicable" value="40" /></td>
    <td class="col-chk"><input name="ctl00" type="checkbox" class="checklistitem" title="Fixed" value="40" /></td>
    <td class="col-chk"><input name="ctl00" type="checkbox" class="checklistitem" title="OK" value="40" /></td>
    <td class="col-flag flag-red"><input name="ctl00" type="hidden" id="ctl00" value="True" /></td>
    <td class="col-question">8 (40).<a href="#" onclick="ChecklistNavigate('photos');return false;">link</a> <a href="#" onclick="showComments('40', 'ctl00');return false;">notes</a><input name="ctl00" type="hidden" id="ctl00" /></td>
</tr>

<tr valign="top" class="">
    <td class="col-status status-yellow">&nbsp;</td>
    <td class="col-chk"><input name="ctl00" type="checkbox" class="checklistitem" title="Not Applicable" value="380" /></td>
    <td class="col-chk"><input name="ctl00" type="checkbox" class="checklistitem" title="Fixed" value="380" /></td>
    <td class="col-chk"><input name="ctl00" type="checkbox" class="checklistitem" title="OK" value="380" /></td>
    <td class="col-flag flag-notset"><input name="ctl00" type="hidden" id="ctl00" value="True" /></td>
    <td class="col-question">23 (380).<a href="#" onclick="ChecklistNavigate('photos');return false;">link</a> <a href="#" onclick="showComments('380', 'ctl00');return false;">notes</a><input name="ctl00" type="hidden" id="ctl00" /></td>
</tr>

<tr valign="top" class="">
    <td class="col-status status-yellow">&nbsp;</td>
    <td class="col-chk"><input name="ctl00" type="checkbox" class="checklistitem" title="Not Applicable" value="20" /></td>
    <td class="col-chk"><input name="ctl00" type="checkbox" class="checklistitem" title="Fixed" value="20" /></td>
    <td class="col-chk"><input name="ctl00" type="checkbox" class="checklistitem" title="OK" value="20" /></td>
    <td class="col-flag flag-red"><input name="ctl00" type="hidden" id="ctl00" value="True" /></td>
    <td class="col-question">6 (20).<a href="#" onclick="ChecklistNavigate('photos');return false;">link</a> <a href="#" onclick="showComments('20', 'ctl00');return false;">notes</a><input name="ctl00" type="hidden" id="ctl00" /></td>
</tr>

まあ、それはコードのほんの一部です。これらのブロック (または、私は「質問」と呼んでいます) は約 100 個あります。上記の例では、質問 40、380、および 20 の 3 つの質問があります。

私が探しているのは、フラグが立てられた質問の数です。上記の例では、40 と 20 の 2 つのフラグ付きの質問があります。これは、属性「flag-red」によって示されます。私がこれまでに持っているものは次のとおりです。

var flaggedRed2 = document.getElementsByClassName("flag-red");
window.alert(flaggedRed2.length);

そして、これは機能します。でも!さて、トリッキーな部分:私が本当に探しているのは、フラグが立てられた質問の数ですが、特定の質問からのみです。たとえば、私は質問 40 (またはその他のいくつかの質問) は気にしません。私はそれを無視したい。ウィンドウアラートに次のように伝えたい: 1.

これは可能ですか?ご覧のとおり、"flag-red" クラスには、各 "tr" の他のクラスとは異なり、問題番号が関連付けられていません。残念ながら、それを HTML コードに追加することはできません。

洞察力があるかもしれない人には、事前に感謝します。

4

2 に答える 2