我正在尝试从 Jquery 对话框 Ok
按钮调用一个函数。
这两种方法我都试过了,
1
this.commentDialog = function(){
$("#commentDialog").dialog( "destroy" );
html = "<div id='cmtDialog'>";
html += "Comment<textarea id='comment'></textarea></div>";
$("#commentDialog").html(html);
$("#commentDialog").dialog({
title:"Search Result",
bgiframe: true,
height: 'auto',
width: 'auto',
modal: true,autoOpen: true,
buttons: { "Ok": function() { this.saveComment();}}
});
2
this.commentDialog = function(){
$("#commentDialog").dialog( "destroy" );
html = "<div id='cmtDialog'>";
html += "Comment<textarea id='comment'></textarea></div>";
$("#commentDialog").html(html);
$("#commentDialog").dialog({
title:"Search Result",
bgiframe: true,
height: 'auto',
width: 'auto',
modal: true,autoOpen: true,
buttons: { "Ok": function() { saveComment();}}
});
两个都不行!
我应该如何使用 jquery 来实现!!
谢谢!!!
最佳答案
this.commentDialog = function(){
// save a reference of "this" and use it later.
var me = this;
$("#commentDialog").dialog( "destroy" );
html = "<div id='cmtDialog'>";
html += "Comment<textarea id='comment'></textarea></div>";
$("#commentDialog").html(html);
$("#commentDialog").dialog({
title:"Search Result",
bgiframe: true,
height: 'auto',
width: 'auto',
modal: true,autoOpen: true,
buttons: { "Ok": function() {
// use me instead of this, as this now refers to the function.
me.saveComment();}}
});
关于javascript - 如何使用 jQuery Dialog OK 按钮调用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4298087/