我在运行时生成了几个框,我想确认所有框是否都是“空的”,那么用户应该无法继续。但是,即使单个 Box包含正确的值(而不是 Empty),那么用户应该能够继续。
我创建了以下代码:
$(document).ready (function () {
setProceedState();
});
function setProceedState() {
if ($('.type').length == $('.type:empty').length) {
alert("Empty" + $(".type").html());
$("#stepAutomapConfirm").attr("disabled", true);
$("#stepAutomapConfirm").addClass("disabled").removeClass("active");
} else {
alert("NOT Empty" + $(".type").html());
$("#stepAutomapConfirm").attr("disabled", false);
$("#stepAutomapConfirm").addClass("active").removeClass("disabled");
}
}
不知何故,这段代码在小提琴中运行良好:http: //jsfiddle.net/aasthatuteja/xJtAV/
但是在我的MVC Partial View页面上它没有完全工作:
如果盒子是“空的”,它总是会给我正确的警报,
但是当它在运行时生成包含数据的框时,它仍然显示“EMPTY”警报。我也检查了“查看源代码”和“检查元素”,在源代码中数据确实存在,然后,当我手动刷新页面时,它会给出正确的警报“ NOT Empty ”。
请建议我缺少什么或JQuery " :empty
" 的替代方法以使代码在MVC 部分视图中工作!
如果您需要任何其他信息,请告诉我!