关闭Fancybox Popup后如何在输入字段中保留值?

时间:2014-11-01 07:42:43

标签: javascript jquery fancybox

我希望在表单提交后保留输入字段中提交的值。当我再次打开它没有显示任何内容时,我知道原因是它每次都会生成一个新的。有办法吗?我在下面尝试过的代码:

function openEditSummaryPoPup(clickHandle,contentHandle,width,height)
{
    width = typeof a !== 'undefined' ? a : 600;
    height = typeof b !== 'undefined' ? b : 300;

    $.fancybox(
        $(contentHandle).html(),
        {
            'width'             : width,
            'height'            : height,
            'minWidth'          :  width,
            'minHeight'         :  height,
            'autoScale'         : true,
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'hideOnContentClick': false,
            'beforeLoad': function ()
            {
               console.log("Content of globalvar = "+globalvar)
                $(".fancybox-wrap .content #txtEditSummary").val('Goodbye Folks!!') //doesnt work
                $(" #txtEditSummary").val('Goodbye Folks in Edit!!')  //doesnt work
            },
            'beforeClose': function()
            {
                globalvar = 'Goodbye Folks in Edit!!';
                $(".fancybox-wrap .content #txtEditSummary").val('Goodbye Folks!!') //doesnt work
                $(" #txtEditSummary").val('Goodbye Folks in Edit!!')
            },
            afterLoad: function ()
            {
                console.log("Loading..."+$("#txtEditSummary").val());
                console.log($(".fancybox-wrap .content #txtEditSummary").val());

                $(".fancybox-inner").on("click", "#btnClose", function ()
                {
                    parent.$.fancybox.close();
                });
                $(".fancybox-inner").on("click", "#btnEdit", function ()
                {

                    var inputSummary = $(".fancybox-wrap .content #txtEditSummary").val();

                    var event_id = $(".fancybox-wrap .content #event_id").val();
                    $.post( "/event/update/", { summary: inputSummary, id: event_id },function( data )
                        {
                            $("#summary").html(inputSummary);
                            updatePOPUPFields({field:'txtEditSummary',value:inputSummary});
                        }
                    );
                    parent.$.fancybox.close();
                });
            }
        }
    );
}

1 个答案:

答案 0 :(得分:1)

好的,我终于找到了。我所要做的就是在AfterShow事件中设置值。那样的东西:

afterShow: function()
            {
                $(".fancybox-wrap .content #txtEditSummary").val(globalvar);
            },