简体   繁体   English

javascript按钮在关闭后停止工作

[英]javascript button stops working after close

I have a button that opens a dialog and when I close the dialog it stops working. 我有一个打开对话框的按钮,当我关闭对话框时它将停止工作。 When I save on the dialog screen it continues to work fine. 当我保存在对话框屏幕上时,它仍然可以正常工作。

This is the button that opens the dialog: 这是打开对话框的按钮:

<button class="actionbutton" type="button" onclick="addLitigant();">Add Litigant To Case(s)</button>

The code it calls: 它调用的代码:

function addLitigant(){
    console.log("Calling addLitigant()");
    editDialog.extendedDialog('loadUrl','CRFilingLitigantDialog.do?action=addLitigant', 'Add Litigant');
}

The close code on the dialog screen: 对话框屏幕上的关闭代码:

param['buttons'].push(
        {
            id: "closeButton",
            text: "(C)lose",
            accessKey: "c",
            click: function () {
                jQuery(this).extendedDialog('close');
                jQuery(this).html('');

            }
        }
    );

The save button code: 保存按钮代码:

function () { 
                        console.log("clicking Save");
                        jQuery('#toAssign option').each(function(){
                            jQuery(this).attr('selected',true);
                        });

                        jQuery('#toUnassign option').each(function(){
                            jQuery(this).attr('selected',true);
                        });

                        editDialog.extendedDialog('postUrl', {url: 'CRFilingLitigantDialog.do?action=updateLitigant', formId: '#crFilingLitigantDialogForm', success: function(){
                            litigantTabGet('CRFilingLitigantDetail.do', null);
                            editDialog.extendedDialog ('destroy');
                        }});
                    }

We are using jquery 1.6.2. 我们正在使用jQuery 1.6.2。 I have tried adding console.log statements to the addLitigant() function but when I come back from the close it doesn't call anything in the console. 我尝试将console.log语句添加到addLitigant()函数中,但是当我从关闭状态回来时,它在控制台中未调用任何内容。 If I refresh the page it does begin to work again until we close from the dialog. 如果刷新页面,它将再次开始工作,直到从对话框关闭为止。

This is the immediate function that is on the page that opens the dialog 这是打开对话框的页面上的即时功能

jQuery(function(){
    console.log("function");

    verificationDialog = jQuery('<div id="verificationDialog"></div>').clerkReviewDialogTemplate({
        height:600,
        width:800,
        title: "Compare Eflex and Icis"
    });

    compareDialog = jQuery('<div id="comparisonDialog"></div>').clerkReviewDialogTemplate({
        height:400,
        width:500,
        title: "Imported Person"
    });

    editDialog = jQuery('<div id="editDialog"></div>').clerkReviewDialogTemplate({
        height:600,
        width:700,
        title: "Edit Litigant",
        buttons: [
            {
                id: "save",
                text: "S(a)ve",
                accessKey: "a",
                click: function () { 
                    console.log("clicking Save");
                    jQuery('#toAssign option').each(function(){
                        jQuery(this).attr('selected',true);
                    });

                    jQuery('#toUnassign option').each(function(){
                        jQuery(this).attr('selected',true);
                    });

                    editDialog.extendedDialog('postUrl', {url: 'CRFilingLitigantDialog.do?action=updateLitigant', formId: '#crFilingLitigantDialogForm', success: function(){
                        litigantTabGet('CRFilingLitigantDetail.do', null);
                        editDialog.extendedDialog ('destroy');
                    }});
                }
            }
        ]
    });

    jQuery('.saveOnChange').bind('change', function(){
        updateLitigants();
    });

    jQuery('.pin').icisAutocomplete({
        mustMatch: true,
        source: function(request, response){
            getQuickAccess(request, response);
        },
        change: function(event, ui){
            updateLitigants();
        }}).each(function(index){
            var data = jQuery(this).data('staging-json');

                jQuery(this).bind('keydown', function(event){
                    return f5_handler({
                        event: event,
                        onf5key: function(){
                            var popup = people_popup({elem: this, event: event, data: data, success: function(data){
                                if(data['pin'] != 'null'){
                                    jQuery(event.currentTarget).val(data['pin']);
                                }
                                if(data['masterPin'] != 'null'){
                                    jQuery('#'+jQuery(event.currentTarget).attr('masterPinField')).val(data['masterPin']);
                                }
                                compareDialog.extendedDialog('close');
                                updateLitigants();
                            }});
                            compareImportedLitigant(data['id'], popup);
                        }
                    });
                });
        });
});

Thanks, 谢谢,

Tom 汤姆

looks like a post back issue that makes you lose you bind events - this is the only thing that could cause losing button event - try to replace your immediate function with 看起来像一个回发问题,使您失去绑定事件-这是唯一可能导致按钮事件丢失的事情-尝试将您的即时函数替换为

function pageLoad() {}

see this $(document).ready() and pageLoad() are not the same! 看到这个$(document).ready()和pageLoad()不一样!

might help 可能有帮助

I compared this code to an older version. 我将此代码与旧版本进行了比较。 I noticed that it worked in an older version and I compared the two. 我注意到它在较旧的版本中有效,我将两者进行了比较。 The older version had a change in the edit dialog code, I added the close code to it and it now works. 较旧的版本在编辑对话框代码中进行了更改,我向其中添加了关闭代码,现在可以使用了。

 editDialog = jQuery('<div id="editDialog"></div>').clerkReviewDialogTemplate({
            height:600,
            width:700,
            title: "Edit Litigant",
            close: function(){
                litigantTabGet('CRFilingLitigantDetail.do', null);
                editDialog.extendedDialog ('destroy').remove();
            },
            buttons: [
                {
                    id: "save",
                    text: "S(a)ve",
                    accessKey: "a",
                    click: function () {
                        jQuery('#toAssign option').each(function(){
                            jQuery(this).attr('selected',true);
                        });

                        jQuery('#toUnassign option').each(function(){
                            jQuery(this).attr('selected',true);
                        });

                        editDialog.extendedDialog('postUrl', {url: 'CRFilingLitigantDialog.do?action=updateLitigant', formId: '#crFilingLitigantDialogForm', success: function(){
                            litigantTabGet('CRFilingLitigantDetail.do', null);
                            editDialog.extendedDialog ('destroy');

                        }});
                    }
                }
            ]
        });

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

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