我正在尝试检测 3 个 div 是否为空,如果它们都有一些内容,则激活一个按钮。
function checkContent()
{
if (!$.trim($('#Div1').html()).length && !$.trim($('#Div2').html()).length && !$.trim($('#Div3').html()).length)
{
console.log("Ready");
$('#nextbutton').prop("disabled", false);
}
else
{
console.log("Not Ready");
}
}
所以我向 Div1 添加了一些内容,控制台显示,尚未准备好。有些到 div 2 还没有准备好。还有一些到 div 3(现在应该已经准备好了),但仍然说未准备好。
不确定我做错了什么,有什么想法吗?
最佳答案
从下面删除不条件
if ($.trim($('#Div1').html()).length > 0 && $.trim($('#Div2').html()).length > 0 && $.trim($('#Div3').html()).length > 0) {
console.log("Ready")
$('#nextbutton').prop("disabled", false);
} else {
console.log("Not Ready")
}
关于jquery - 使用jquery检测div中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23563866/