我有一个 jquery 函数,其中我声明了一个变量并使其默认为 false。然后在 If 条件中我为该变量分配 true 值。但我总是得到 false..为什么会这样? ?当使用警报时,我得到“true”,但在 if 条件下它是“false”
这是我的代码:
var abc = false
$('#dataTable tr td').find("input[name='" + 'lstDetlIssue[' + i + '].Product' + "']").change(function () {
abc = true;
alert(abc);
});
if (MstCopyParseData[rowIndex].ProductID == MstCopyParseData[parseInt(i)].ProductID && (i != rowIndex && (MstCopyParseData[i].Product != "" && abc == true ))) {
最佳答案
$('#dataTable tr td').find("input[name='" + 'lstDetlIssue[' + i + '].Product' + "']").change(function () {
abc = true;
alert(abc); // true here
});
false here
ABC 在这个函数中是 true,但在这个函数之外是 false,因为你默认将它设置为 false...这就是为什么你得到 false....如果你想要 abc 为 true,那么你应该把你的“if” "上述函数内的条件
关于javascript - 如何比较 JavaScript 中的变量值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42337199/