1

我有一个循环遍历 div 中的项目的每个循环。

$(":radio[id^=lt]:checked,:hidden[id^=lt]", "#entry_"+item_id).each(function() {
    // Get values here
});

我将如何修改循环代码以仅获取父 tr 未隐藏的那些(参见下面的 CT)?输入可以是单选或隐藏类型。

<div class="entry" style="" id="entry_1117178">
    <table width="100%">
        <tbody>
            <tr>
                <td align="right"><label class="lbl_ln" for="lname_1117178" id="null_1117178">Name on License:&nbsp;</label></td>
                <td align="left"><input type="text" name="lname" class="lname" id="lname_1117178"></td>
            </tr>
            <tr>
                <td align="right"><label class="lbl_lic" for="ln_1117178" id="lbl_1117178">License:&nbsp;</label></td>
                <td align="left"><input type="text" class="ln" name="ln" id="ln_1117178"></td>
            </tr>
            <tr class="InfoCol" id="InfoCol_AL" style="display: none;">
                <td class="TypeCol" id="InfoType_220574">
                    <input type="hidden" class="lt_" id="lt_1117178_220574" name="lt_1117178_220574" value="220574">
                    <label id="lbl_lt_220574" class="lt_" for="lt_1117178"></label>
                </td>
            </tr>
            <tr class="InfoCol" id="InfoCol_CT" style="display: table-row;">
                <td class="TypeCol" id="InfoType_181258">
                    <input type="hidden" class="lt_" id="lt_1117178_181258" name="lt_1117178_181258" value="181258">
                    <label id="lbl_lt_181258" class="lt_" for="lt_1117178"></label>
                </td>
            </tr>
            <tr class="InfoCol" id="InfoCol_DC" style="display: none;">
                <td class="TypeCol" id="InfoType_183820">
                    <input type="radio" class="lt_" id="lt_1117178_183820" name="lt_1117178_183820" value="183820">
                    <label id="lbl_lt_183820" class="lt_" for="lt_1117178_183820">Item 1</label>
                </td>
                <td class="TypeCol" id="InfoType_183821">
                    <input type="radio" class="lt_" id="lt_1117178_183821" name="lt_1117178_183821" value="183821">
                    <label id="lbl_lt_183821" class="lt_" for="lt_1117178_183821">Item 2</label>
                </td>
            </tr>
        </tbody>
    </table>
</div>

在上面的代码的情况下,我只想获取 ID=lt_1117178_181258 的输入的值

4

2 回答 2

3
$(":radio[id^=lt]:checked,:hidden[id^=lt]", "#ce_entry_"+item_id).each(function() {
    if ( $(this).closest('tr').is(':visible') ) {
        // Get values here
    }
});
于 2013-02-15T17:50:01.167 回答
1

这似乎更清洁:

$("input", ".InfoCol:visible").each(function() {
  //whatever
});

它可能有点过于简化,但根据您展示的 html,我认为它可能会工作......

于 2013-02-15T17:53:57.270 回答