$ .each()只获取其父级未隐藏的项目

时间:2013-02-15 17:49:06

标签: jquery

我有一个循环遍历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

的输入值

2 个答案:

答案 0 :(得分:3)

$(":radio[id^=lt]:checked,:hidden[id^=lt]", "#ce_entry_"+item_id).each(function() {
    if ( $(this).closest('tr').is(':visible') ) {
        // Get values here
    }
});

答案 1 :(得分:1)

这似乎有点清洁:

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

它可能有点过于简化了,但基于您展示的html,我认为它可能有效......