[英]Issue Traversing Through Table with jQuery
我試圖通過讓jQuery函數遍歷每一行,檢查一行的類並基於此進行隱藏來隱藏表中的元素。 我似乎遇到的問題是該函數將檢查第一行的類,並基於所有其他檢查來隱藏該第一檢查是true還是false。 下面是函數和表單的一部分
表格
<select id="select" onchange="eligibility_changed(this);" class="fieldsel">
<option value="Select One:">Select One:</option>
<option value=".ineligible">Ineligible</option>
<option value=".eligible">Eligible</option>
<option value=".confirmed">Eligible</option>
</select>
和功能
function eligibility_changed($this) {
jQuery(".fieldsel").each(function() {
var col = this.id;
var val = this.value;
console.log(val);
if (val != "Select One:") {
jQuery("#tbl>tbody>tr").each(function() {
//Ran to check the row's class.
console.log(jQuery('#eligfld').attr('class'));
if (!jQuery( "#eligfld" ).is(val)) {
jQuery(this).hide();
}
});
}
});
};
假設行具有您在選項中顯示的類,則無需循環所有行,只需隱藏該類
if (val != "Select One:") {
// show all, filter for class and hide that class
jQuery("#tbl>tbody>tr").show().filter(val).hide();
}
這是與ID無關的,因此除非您有多個具有相同ID的表,否則重復ID不會成為問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.