我有以下HTML:
<div id="referenceResolverDialog" title="Resolve IDs">
<p>Please fill in a comma separated list of IDs.</p>
<form>
<fieldset>
<textarea name="referenceResolverTextArea" id="referenceResolverTextArea" rows="6" cols="54"></textarea>
</fieldset>
</form>
</div>
我创建了jQuery对话框,如下所示:
var configParams = {
// some config properties
textAreaSelector: '#referenceResolverTextArea',
// some other config properties
}
var form, dialog;
dialog = $(configParams.dialogSelector).dialog({
autoOpen: false,
height: 220,
width: 350,
modal: true,
buttons: {
"Resolve": ResolveDialogData,
Cancel: function () {
dialog.dialog("close");
}
},
close: function () {
form[0].reset();
dialog.dialog("close");
}
});
form = dialog.find("form").on("submit", function (event) {
event.preventDefault();
ResolveDialogData(configParams);
});
问题是configParams
作为新对象传递,而不是我已经拥有的对象。在ResolveDialogData()
方法中,我有以下内容:
function ResolveDialogData(configParams) {
alert(configParams); // returns [object Object]
alert(configParams.textAreaSelector); // returns undefined
}
我做错了什么?
答案 0 :(得分:1)
如果您从“解决”按钮进入回调,则configParams
参数将代表对话框传递的Event
对象。
更改
buttons: {
"Resolve": ResolveDialogData,
Cancel: function () {
dialog.dialog("close");
}
},
到
buttons: {
"Resolve": function(e) { // e is the object you were ending up with before
ResolveDialogData(configParams);
},
Cancel: function () {
dialog.dialog("close");
}
},