我根据对“选择”字段的更改在 jQuery 对话框中启用“确定”按钮。
该部分有效,但是当我单击“确定”或“关闭”以保存该信息并继续时,会出现以下错误。
Chrome: Uncaught TypeError: Cannot read property 'apply' of undefined
Firefox: TypeError: d.click is undefined
... e="button">').click(function(){d.click.apply(c.element[0],arguments)})....
jquery-ui.min.js (line 14, col 5350)
var disposition; // I'm using this so that the alert('fixed') doesn't get call on load...
// Callback Disposition Dialog
$('#disposition_modal').dialog({
open: function () { // removed the default close link
$(this).parent().children(':first').children('a').remove();
},
buttons: [{
text: 'Cancel',
Ok: function () {
$(this).dialog("close");
}
}, {
text: 'OK',
disabled: true,
id: 'dm_btn',
Ok: function () {
if (disposition !== '' && undefined !== disposition) {
alert('fixed');
$(this).dialog("close");
}
}
}]
});
// toggle the OK button
$('#disposition_id_in2').change(function () {
disposition = $('#disposition_id_in2').val();
if ($('#disposition_id_in2').val()) {
$('#dm_btn').attr('disabled', false);
} else {
$('#dm_btn').attr('disabled', true);
}
});
这里是 JSFiddle 对该问题的最低限度提炼:JSFiddle button error
最佳答案
您需要将按钮的“确定”更改为“单击”。
buttons: [{
text: 'Cancel',
click: function () {
$(this).dialog("close");
}
}, {
text: 'OK',
disabled: true,
id: 'dm_btn',
click: function () {
console.log(disposition);
if (disposition !== '' && undefined !== disposition) {
alert('fixed');
$(this).dialog("close");
}
}
}]
关于javascript - jQuery 错误 "Uncaught TypeError: Cannot read property ' 未定义的应用',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29993196/