我有幾個過濾器可以顯示或隱藏表中的錶行,然後檢查是否沒有可見的行,然後向表中添加一條消息表示不存在行。如何在JavaScript中強制執行下一行之前的行?
這是我如何去做,但慘敗失敗,也許我不知道與JS執行線的方式,也許異步總是?
HTML
<input ID="cbFreshFruits" Checked="true" onclick="ToggleFruits(this)" />
腳本
function ToggleFruits(elm) {
$target = $('#fruitTable tr[data-status="' + elm.id + '"]').filter(function() {
var crates = $("#crateTable tr .selected").parent().map(function() {
return $(this).data("crateID");
}).get();
return crates.indexOf($(this).data("crateID")) >= 0;
});
if (elm.checked) {
$target.show("down");
}
else {
$('#fruitTable tr[data-status="' + elm.id + '"]').hide("up");
}
CheckFruitExists();
}
function CheckFruitExists() {
$("#NoFilteredFruits").hide();
$("#fruitTable").show();
if ($("#fruitTable tr:visible").length < 1) {
$("#NoFilteredFruits").show();
$("#fruitTable").hide();
}
}
問題
當開發者工具檢查,JS執行該語句
if ($("#fruitTable tr:visible").length < 1)
此人之前,
else {
$('#fruitTable tr[data-status="' + elm.id + '"]').hide("up");
}
我的意思是執行它,但它的變化是不言,例如它在執行語句之前不會隱藏任何行。
請注意,我在不同的地方使用CheckFruitExists
,所以我想保持分開。
HTML ** END UP **如何呈現給頁面?我從來沒有聽說過一個標籤。 –
Jhecht
2014-08-27 09:36:26
你如何確認執行流程? – Vishwanath 2014-08-27 09:37:16
@Vishwanath 使用開發人員工具檢查了它,提到已經存在問題:-) – Mathematics 2014-08-27 09:47:36