确定是否所有 jQueryUI 复选框(按钮)都未选中
Determine if all jQueryUI checkboxes(buttons) are unchecked
我有一系列由 html 呈现的 jQueryUI 复选框,如下所示...
<input class="asset-tile-select-input" id="asset-tile-select-input-84" type="checkbox"
name="asset-tile-select">
<label for="asset-tile-select-input-84"></label>
我让他们一起...
$("input[id*='asset-tile-select-input']").button(
{
text: false
});
然后,每当(我认为)框是 un/checked 时,我使用以下内容来确定我是否应该 show/hide 一个相关元素...
$("input[id*='asset-tile-select-input']").change(
function()
{
if( $("input[id*='asset-tile-select-input']:checked") )
{
alert("asdf");
if( $("#box-asset-icon-container").is(":visible") == false )
{
$("#box-asset-icon-container").show(300);
}
}
else
{
if( $("#box-asset-icon-container").is(":visible") == true )
{
$("#box-asset-icon-container").hide(300);
}
}
});
只是,无论我选中还是取消选中该框,都会触发警报。为什么?它以一种方式工作,因为如果选中某些内容,它将 .show() 相关元素。我该如何设置它才能知道是否所有类似的复选框都未选中并隐藏相关的#box-asset-icon-container 元素?
这里的问题是 $("input[id*='asset-tile-select-input']:checked")
是一个对象。使用 $("input[id*='asset-tile-select-input']:checked").length > 0
代替
我有一系列由 html 呈现的 jQueryUI 复选框,如下所示...
<input class="asset-tile-select-input" id="asset-tile-select-input-84" type="checkbox"
name="asset-tile-select">
<label for="asset-tile-select-input-84"></label>
我让他们一起...
$("input[id*='asset-tile-select-input']").button(
{
text: false
});
然后,每当(我认为)框是 un/checked 时,我使用以下内容来确定我是否应该 show/hide 一个相关元素...
$("input[id*='asset-tile-select-input']").change(
function()
{
if( $("input[id*='asset-tile-select-input']:checked") )
{
alert("asdf");
if( $("#box-asset-icon-container").is(":visible") == false )
{
$("#box-asset-icon-container").show(300);
}
}
else
{
if( $("#box-asset-icon-container").is(":visible") == true )
{
$("#box-asset-icon-container").hide(300);
}
}
});
只是,无论我选中还是取消选中该框,都会触发警报。为什么?它以一种方式工作,因为如果选中某些内容,它将 .show() 相关元素。我该如何设置它才能知道是否所有类似的复选框都未选中并隐藏相关的#box-asset-icon-container 元素?
这里的问题是 $("input[id*='asset-tile-select-input']:checked")
是一个对象。使用 $("input[id*='asset-tile-select-input']:checked").length > 0
代替