0

这里我定义了一个函数来处理 JQueryUI 对话框按钮上的单击事件

$.fn.MenuItemRemove = function () {
$('#dialogMessage').dialog('close');
ajaxData = JSON.stringify(MenuItemAction);
$.ajax(
{
    type: "POST",
    url: "/DynaStructure/LayoutMenuItemRemoveItem/" + $("#hidLanguage").val(),
    data: ajaxData,
    contentType: "application/json",
    async: false,
    success: $.fn.MenuUpdated,
    error: function (xhr, ajaxOptions, thrownError) {
        $.fn.jqDialogAlert(cap_DialogErrorTitle, (xhr.responseText));
    }
});
}

这是我的 JQuery UI Confim 对话框的代码

$.fn.jqDialogConfirm = function (title, message, confirmButtonTitle, cancelButtonTitle, okFunction, height, width) {
/// <summary>
/// Simple confirmation dialog box
/// </summary>
/// <param name="title" type="String">
/// Title of the dialog
/// </param>
/// <param name="message" type="String">
/// Message to display
/// </param>
/// <param name="confirmButtonTitle" type="String">
/// Confirm button title
/// </param>
/// <param name="cancelButtonTitle"type="String">
/// Cancel button title
/// </param>
/// <param name="okFunction" type="function">
/// Function called when Ok button clicked
///</param>
///<param name="width" type="int">
/// Width in pixels of the dialog box (default : defaultSmallDialogWidth)
///</param>
///<param name="height" type="int">
/// Height in pixels of the dialog box (default : defaultSmallDialogHeight)
///</param>
if (width == null) { width = defaultSmallDialogWidth; }
if (height == null) { height = defaultSmallDialogHeight; }
var dialogBox = $('#dialogMessage');
dialogBox.text(message);
$(dialogBox).hide();
$(dialogBox).dialog({
    title: title,
    autoOpen: false,
    resizable: false,
    modal: true,
    minHeight: height,
    minWidth: width,
    buttons: [
        {
            text: confirmButtonTitle,
            click: okFunction
        }
        ,
        {
            text: cancelButtonTitle,
            click: function () {
                $(this).dialog("close");
            }
        }
    ]
});
dialogBox.dialog('open');}

这里调用我的确认对话框:

$.fn.jqDialogConfirm("Are you sure ?", "Are you really sure  ?", "Ok","Cancel", "$.fn.MenuItemRemove", null, null);

当我单击 Ok 按钮时,JavaScript 调试器在 jquery-ui-1.9.2 第 9418 行停止:

    if ( hasButtons ) {
        $.each( buttons, function( name, props ) {
            var button, click;
            props = $.isFunction( props ) ?
                { click: props, text: name } :
                props;
            // Default to a non-submitting button
            props = $.extend( { type: "button" }, props );
            // Change the context for the click callback to be the main element
            click = props.click;
            props.click = function() {
                click.apply( that.element[0], arguments ); //<<<<<HERE
            };
            button = $( "<button></button>", props )
                .appendTo( that.uiButtonSet );
            if ( $.fn.button ) {
                button.button();
            }
        });
        this.uiDialog.addClass( "ui-dialog-buttons" );
        this.uiDialogButtonPane.appendTo( this.uiDialog );
    } else {
        this.uiDialog.removeClass( "ui-dialog-buttons" );
    }
},

随着消息:

行:9418 错误:对象不支持属性或方法«应用»

你能帮我解决这个问题吗?

4

2 回答 2

1

你的电话不正确:

$.fn.jqDialogConfirm([snipped], "$.fn.MenuItemRemove", null, null);

okFunction需要是一个函数,但你正在传递一个字符串。你应该通过:

$.fn.jqDialogConfirm([snipped], $.fn.MenuItemRemove, null, null);

附带说明一下,不建议将应用程序逻辑放在 jQuery 命名空间中。我会亲自投入MenuItemRemove什么的MyApp.MenuItemRemove

于 2013-06-24T09:16:34.037 回答
0

抱歉,我发现了问题:

$.fn.jqDialogConfirm("Are you sure ?", "Are you really sure  ?", "Ok","Cancel", "$.fn.MenuItemRemove", null, null);

引号必须从函数调用中删除`

$.fn.jqDialogConfirm("Are you sure ?", "Are you really sure  ?", "Ok","Cancel", $.fn.MenuItemRemove, null, null);
于 2013-06-24T09:38:37.520 回答