Javascript jQuery 错误“未捕获的类型错误:无法读取未定义的属性‘应用’”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29993196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery error "Uncaught TypeError: Cannot read property 'apply' of undefined"
提问by marklark
I'm enabling an OK button in a jQuery dialog box based on changes to a Select field.
我正在基于对 Select 字段的更改在 jQuery 对话框中启用 OK 按钮。
That part works, but when I click on OK or 'Close' in order to save that information and proceed, the following errors appear.
该部分有效,但是当我单击“确定”或“关闭”以保存该信息并继续时,会出现以下错误。
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)
Chrome:未捕获的类型错误:无法读取未定义的属性“应用”
Firefox:类型错误:d.click 未定义
... e="button">').click(function(){d.click.apply(c.element[0],arguments)})....
jquery-ui.min.js(第 14 行,第 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);
}
});
Here's a JSFiddle distillation of the problem to its barest minimum: JSFiddle button error
这是 JSFiddle 对问题的最低限度的提炼:JSFiddle 按钮错误
采纳答案by John S
You need to change "Ok" to "click" for the buttons.
您需要将按钮的“确定”更改为“单击”。
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");
}
}
}]

