如果我的两个字段都有keydown事件,我正在尝试启用按钮。下面是我尝试但不起作用的代码。有任何想法吗 ?
var dateField = 0;
var termOfPaymentField = 0;
$(jq('overlay.givendate'))
.on('change keydown', function () {
dateField = 1;
});
$(jq('overlay.fielddata'))
.on('change keydown', function () {
termOfPaymentField = 1;
});
if (dateField === 1 && termOfPaymentField === 1) {
$('.ui-dialog-buttonpane button').button({ disabled: false });
dateField = 0
termOfPaymentField = 0;
}
答案 0 :(得分:2)
除了设置标志外,您还需要运行if
条件。试试这个:
var dateFieldChanged = false;
var termOfPaymentFieldChanged = false;
$(jq('overlay.givendate')).on('change keydown', function () {
dateFieldChanged = true;
checkFields();
});
$(jq('overlay.fielddata')).on('change keydown', function () {
termOfPaymentFieldChanged = true;
checkFields();
});
function checkFields() {
if (dateFieldChanged && termOfPaymentFieldChanged) {
$('.ui-dialog-buttonpane button').button({ disabled: false });
dateFieldChanged = false;
termOfPaymentFieldChanged = false;
}
}
注意我也将标志更改为布尔值。