0

我有一个链接如下:

<div id="demo-testpack">
          <a href="#" class="user-not-loggedin">Demo Test Packages</a>
      </div>

单击此链接时,我将调用以下 jQuery 代码:

$(function() {  
  $("#user-popup-login").dialog({ autoOpen: false }); 
  $( ".user-not-loggedin" )
    .click(function() {
    $( "#user-popup-login" ).dialog( "option", "width", 400 );
    $( "#user-popup-login" ).dialog( "option", "modal", true );
    $( "#user-popup-login" ).dialog( "open" );

    return false;
  });

使用此功能后,弹出窗口会打开,弹出窗口中有一些字段和一些链接。弹出窗口中的一个链接如下:

<div id="registern"><a href="#" class="register-btn">Register Now</a></div>

单击此链接时,我想执行以下代码,从而打开另一个弹出窗口。jQuery 代码如下:

$(function() {  
    $("#create-user-form").dialog({ autoOpen: false }); 
    $( ".register-btn" )
        .click(function() {
        $( "#create-user-form" ).dialog( "option", "width", 560 );
        $( "#create-user-form" ).dialog( "option", "modal", true );
        $( "#create-user-form" ).dialog( "open" );

        return false;
    });

    $( ".get-start" )
        .click(function() {
        $( "#create-user-form" ).dialog( "option", "width", 560 );
        $( "#create-user-form" ).dialog( "option", "modal", true );
        $( "#create-user-form" ).dialog( "open" );

        return false;
    });         

    //This function is used to submit User Registration form
    $('#user_registration_form').live('submit', function() { 
         $('.register').attr('disabled', 'disabled');
         show_request('#registration_error');
            $.ajax({   
                type: $(this).attr('method'),
                url: $(this).attr('action'), 
                data:$(this).serialize(),
                dataType: 'json',
                success: function(response) { 
                    $('.register').removeAttr('disabled', 'disabled');
                    var reg_error = response.reg_error;    

                    if(reg_error=='yes') {
                        var error_msg      = response.error_msg; 
                        var dialog_title   = 'Input Errors Found';                 
                        var dialog_message = error_msg; 
                        $("#registration_error").html(error_msg);
                    } else {
                        $("#registration_error").html('');
                        $( "#create-user-form" ).dialog('close');
                        var suc_msg   = response.suc_msg; 
                        var dialog_title   = 'Registered Successfully';                 
                        var dialog_message = suc_msg; 

                        var $dialog = $("<div class='ui-state-success'></div>")
                        .html("<p class='ui-state-error-success'>"+dialog_message+"</p>")
                        .dialog({
                             autoOpen: false,
                             modal:true,
                             title: dialog_title,
                             width: 500,                       
                             buttons:{
                             'OK': function() {
                                $(this).dialog('close');
                                 }
                             }                                             
                        });
                        $dialog.dialog('open'); 
                        $('#user_registration_form')[0].reset();    
                    }

                } 
            });    
            return false;
    }); 
});

现在我想要实现的是,当用户点击上面的链接时,之前打开的弹出窗口应该关闭,并且只有这个新的弹出窗口应该显示。我做了很多技巧,但没有成功。任何人都可以帮助我如何实现这一目标吗?在此先感谢。

4

2 回答 2

0

I'm going to guess this is scope issue because the call to popup('open') on $( "#create-user-form" ) in a different anonymous function than where you are trying to close it. Try putting the calls to open and close it in the same document.ready shorthand anonymous function.

于 2013-05-29T15:36:45.010 回答
0

我试过了,reac这可以通过以下代码片段来实现。这对我来说真的很神奇。

if($( "#user-popup-login" ).dialog( "open" ))
        $( "#user-popup-login" ).dialog( "close" );
于 2013-05-29T16:26:36.567 回答