到目前为止的研究:我发现一个答案建议使用全局变量声明以使全局变量可用于对话框代码,但我认为这是一种霰弹枪方法。我希望专门将一个变量传递到我的 .dialog 框的 close: 。
问题:无法将参数传递到对话框的 close: 部分。
最近我尝试了这段代码,它遵循表单提交():
document.forms['dsEntryForm'].submit();
myTalk.data('timestamp', timestamp); //assign the ID for later
myTalk.dialog("close");
...其中myTalk是分配给我的对话框的变量,timestamp是UTC值,最后我希望它执行一系列操作:
close: function(data){
clearForm(document.forms['dsEntryForm']);
CKEDITOR.instances.editor.setData('');
if(document.getElementById('formsubmitted')){
document.getElementById('formsubmitted').parentNode.removeChild(document.getElementById('formsubmitted'));
}
getNewMessage(data.timestamp);
}
但是,当我使用 alert(data.timestamp);
调试 data.timestamp 的值时,结果是未定义。
最佳答案
对话框close
事件接收参数event
和ui
,没有像您尝试使用的数据。
如果您使用 data-timestamp
属性设置数据,那么您可以在关闭事件中访问它,如下所示:
close: function(){
console.log( $(this).data('timestamp') );
}
关于jquery - 如何将参数传递给 jQuery 对话框 ("close")?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17281708/