English 中文(简体)
我怎么能够把纽芬兰语改写在一个支流式模式中?
原标题:How can I dynamically name buttons in a jquery modal script?

我有以下文字,用于与纽州形成一种模式。 我的行文如下:

$.modal = function(options)
    {
        var settings = $.extend({}, $.modal.defaults, options),
            root = getModalDiv(),

            // Vars for resizeFunc and moveFunc
            winX = 0,
            winY = 0,
            contentWidth = 0,
            contentHeight = 0,
            mouseX = 0,
            mouseY = 0,
            resized, content =   , contentObj;

and then later:

    var buttonsFooter = false;
    $.each(settings.buttons, function(key, value)
    {
        // Button zone
        if (!buttonsFooter)
        {
            buttonsFooter = $( <div class="block-footer align- +settings.buttonsAlign+ "></div> ).insertAfter(contentBlockWrapper);
        }
        else
        {
            // Spacing
            buttonsFooter.append( &nbsp; );
        }

Here s the way I create the modal:

$.modal({
                    title: title,
                    closeButton: true,
                    content: content,
                    complete: function () {
                        applyTemplateSetup();
                        $($( #main-form )).updateTabs();
                    },
                    width: 900,
                    resizeOnLoad: true,
                    buttons: {
                         Submit  : function () {
                            formSubmitHandler($( #main-form ));
                        }
                    }
                });

我想做的是,利用这一文字来建立我与纽州联手的模式,并积极分配纽特的名字。 然而,当我尝试用单体变换代子时,它就做了一些工作。 是否有任何人想我能做什么?

问题回答

The reason replacing Submit with a variable name doesn t work is because the quotes aren t needed when defining an object in that manner (unless the name contains some special characters). var obj = { Submit : function() { } } is exactly the same thing as var obj = { Submit: function() { } }.

您注意到,您在重新通过<代码>的标本中已经删除了这种引文。

然而,虽然你可以写字

var myVariable =  abc ;
var obj = { myVariable: 3 };

页: 1

var myVariable =  abc ;
var obj[myVariable]  = 3;

... and obj.abc will exist.

Thus, you could solve your problem in the following manner:

var buttons = { };

buttons[variableName] = function () {
   formSubmitHandler($( #main-form ));
};

$.modal({
   ...
   buttons: buttons
});

<><>Edit>: David Hedlund请我回答,并提出一个类似的答案,涉及略微少改动法典。 他只建议打破各州的选择,而不是整个选择。 http://www.ohchr.org。

第一,将备选办法分成一个变量:

var modalOpts = {
    title: title,
    closeButton: true,
    content: content,
    complete: function () {
        applyTemplateSetup();
        $($( #main-form )).updateTabs();
    },
    width: 900,
    resizeOnLoad: true,
    buttons: {
         Submit  : function () {
            formSubmitHandler($( #main-form ));
        }
    }
};

$.modal(modalOpts);

然后,将所涉的纽子从这些选择中分离出来,并使用方括号的取用和书写:

var dynamicButtonName =  Submit ; //Or whatever

var modalOpts = {
    title: title,
    closeButton: true,
    content: content,
    complete: function () {
        applyTemplateSetup();
        $($( #main-form )).updateTabs();
    },
    width: 900,
    resizeOnLoad: true,
    buttons: {}
};

modalOpts.buttons[dynamicButtonName] = function () {
    formSubmitHandler($( #main-form ));
};

$.modal(modalOpts);




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签