檢測複選框的可見性狀態時出現問題,我想要求您的幫助。.is(「:visible」)find
我的頁面,它看起來像一個dynamicaly加載部分:
<div id="box">
<div class="colored">
<input type="checkbox" value="f01" name="mycheckbox">
<!-- some content -->
<div>
<div class="colored">
<input type="checkbox" value="f02" name="mycheckbox">
<!-- some content -->
<div>
<!-- .... -->
</div>
這表示,我們應該說,在一些庫項目。每班=「彩色」div可以是可見或隱藏的。 可以說,這是簡單的過濾器,就像我希望有明顯的唯一一類=「有色黃」的div
而現在問題的核心: 我需要通過整個BOX元素循環,找到所有複選框後通過每個複選框,「問他」,如果它是可見的,如果是真的,檢查他。
Unforunately,這不起作用:
function checkallfav() {
$("#box").find('input[type=checkbox]').each(function() {
if (this.is(":visible")) {
this.checked = true;
}
});
}
//And this doesn't work as well
function checkallfav() {
$("#box").find('input[type=checkbox]').is(":visible").each(function() {
this.checked = true;
});
}
的問題是,FIND函數返回整個元素,我想 Console.debug(本);並在螢火蟲,響應是所有html元素
所以,請,任何人都有一個解決方案?
您需要使用'$(本)。是( 「:可見」)' – Satpal
由於兩個答案表明,無論是你的方法可能* *已經工作,你只是在兩個小錯誤。 – Jamiec