简体   繁体   English

从添加到click事件的函数中获取价值

[英]Get value from a function that was added to click event

This is a code in document ready 这是准备好文档中的代码

 $(document).ready(function {

 $('button[id$="btnSave"]').click(function() {
        saveEvent();
    });

    function saveEvent() {
        $.colorbox.close();
        result = { date: $('#txtDate').val(), description: $('#txtDescription').val() }
        return result;
    }
});

Here is where I need this results 这是我需要此结果的地方

 var calendar = $('#calendar').fullCalendar({
    editable: true,
    disableResizing: true,
    loading: function(bool) {
        if (bool) {
            $('#loading').show();
        }
        else {
            $('#loading').hide();
        }
    },
    dayClick: function(date, allDay, jsEvent, view) {


        displayInput($(this), date);// show modal

   //!!return results from modal on mouse click!!

    },
    events: {
        url: 'UserCalendarService.asmx/GetEvents',
        type: 'POST',
        dataType: 'json',            
        contentType: "application/json; charset=utf-8"
    }
});

This works fine, but how can I get this result object in other function when I click on the Save button. 这可以正常工作,但是当我单击“保存”按钮时如何在其他函数中获取此结果对象。 For example, When Colorbox modal is showed, user click on the save button. 例如,当显示“ Colorbox”模态时,用户单击“保存”按钮。 How can I get return value of saveEvent function at that time? 那时如何获取saveEvent函数的返回值?

Later on I'll need a callback to put this user values in calendar ui 稍后,我需要回调以将此用户值放入日历ui中

It seems simple - see comment below. 看起来很简单-请参阅下面的评论。

 $(document).ready(function {

 $('button[id$="btnSave"]').click(function() {
        var returnValue=saveEvent();
        //SEND return value anywhere you want.
    });

    function saveEvent() {
        $.colorbox.close();
        result = { date: $('#txtDate').val(), description: $('#txtDescription').val() }
        return result;
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM