Jquery $.each()仅获取其父项未隐藏的项
我有一个each循环,它循环通过div中的项Jquery $.each()仅获取其父项未隐藏的项,jquery,Jquery,我有一个each循环,它循环通过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 wid
$(":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: </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: </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的输入值,这似乎更简洁了一些:
$(":radio[id^=lt]:checked,:hidden[id^=lt]", "#ce_entry_"+item_id).each(function() {
if ( $(this).closest('tr').is(':visible') ) {
// Get values here
}
});
$("input", ".InfoCol:visible").each(function() {
//whatever
});
它可能有点过于简化,但基于您展示的html,我认为它可能会工作…这似乎有点简洁:
$("input", ".InfoCol:visible").each(function() {
//whatever
});
它可能有点过于简化,但基于您展示的html,我认为它可能会工作…这会得到父级还是可能在代码中稍后得到父级?它会得到DOM中向上最接近的TR,即最接近的父级TR,并检查它是否可见,不隐藏。这会得到父级还是可能在代码后面得到父级?它会得到DOM中最接近的TR,即最接近的父级是TR,并检查它是否可见,而不是隐藏。