从对话框按钮 jquery ui 调用函数

Posted

技术标签:

【中文标题】从对话框按钮 jquery ui 调用函数【英文标题】:calling function from dialog button jquery ui 【发布时间】:2016-01-31 13:54:18 【问题描述】:

DEMO

从对话框调用函数得到is not a function错误

对话框中的按钮点击:

Add: 
    class: 'calendareventleft',
    text: 'Add',
    click: function() 
        var title = $("#title").val();
        var description = $("#description").val();
        var otherinfor = $("#otherinfo").val();
        $(this).ajaxcall(title, description, otherinfor);
    

显示对话框的按钮

$('#button').click(function() 

    $("#dialog").dialog(
        title: "qwe"
    );
    $("#dialog").html("<div>" + "<form>" + "Title:<br>" + "<input type='text' id='title' class='calendarinput'>" + "<br>" + "Description:<br>" + "<textarea id='description' class='calendarinput calendartxtarea'></textarea>" + "<br>" + "Additional Information:<br>" + "<textarea id='otherinfo' class='calendarinput calendartxtarea'></textarea>" + "</form>" + "</div>");
    $("#dialog")
        .dialog("open");


)

我需要运行的函数

function ajaxcall(title, description, otherinformation) 
    consoole.log(title);
    consoole.log(description);
    consoole.log(otherinformation);

【问题讨论】:

【参考方案1】:

您正在调用 $(this).ajaxcall(....),它期望 ajaxcall 是一个插件方法,但这不是错误的原因。

就这样称呼吧

ajaxcall(title, description, otherinfor);

演示:Fiddle

【讨论】:

以上是关于从对话框按钮 jquery ui 调用函数的主要内容,如果未能解决你的问题,请参考以下文章

通过调用 ASP.NET 按钮单击从 jQuery 模态对话框回发

需要从 MVC 5 中的控制器操作关闭 Jquery UI 对话框

jquery-ui 对话框不居中,关闭按钮奇怪的行为

在 Laravel 4 中单击按钮后如何在 jquery 中调用控制器函数

qt修正参数怎么调用自定义函数

动态jQuery UI对话框回调函数问题