0

当用户关闭对话框时,我试图删除对话框中的文本。我在一个页面中有多个对话框,有些对话框里面有表单。其中一个是向用户发送消息,另一个是更新用户详细信息的表单。

提交表单时,表单上方会显示一条关于状态的消息,即它是失败还是成功。

jQuery:

$('form.updateDetailsForm').on('submit', function()
{
    //console.log("hello");
    event.preventDefault();
    var form =  $(this);
    post = form.serialize();
    $.post("",{ form: post, studentHub: true}, function(msg)
    {
        var popUpDialog = form.parent();
        console.log(msg);
        var status = $('.notifications', popUpDialog);

        status
            .html(msg)
            .hide()
            .fadeTo(2500, 1)
            .delay(20000)//<== wait 3 sec before fading out
            .fadeTo(2000, 0, function()
            {
                status.html('');
            }); 
    }); 
    //return false;     

});//END OF updatedetails form submit 

/****For each popuplink we bind the dialog that is ---IMMEDIATELY NEXT--- to it and click event to it.  ***/
$('.popUpLink').each(function()
{
     if(!$.data(this, 'dialog'))//if not bound then we bind it. This is for dynamic issues
     {
        $divDialog = $(this).next('.popUpDialog');

        $.data(this, 'dialog', $divDialog.dialog(
        {
            autoOpen: false,
            modal: true,
            minWidth: '100',
            width: '800',
            hide: 'fold',
            show: 'drop',
            title: $divDialog.attr('title'),     
            close: function() {
                  $('.notifications, div:animated', $divDialog).html(''); //this is what I've tried but it doesn't work. 
            } 
        }));
     }
}).on('click',function() 
{ 
    $.data(this, 'dialog').dialog('open').css('maxHeight', $(window).height()-90);
    return false; 
});

HTML:

<div class="flexi_box">
    <h2 class="sendMessageHeader hubFormHeader">Send a message to your tutor </h2>
    <div class="notifications"></div> //div to insert status updates                                        
    <form class="sendMessageForm" id="tutorForm" action="" method="POST">   
        <fieldset>
            <textarea class="messageArea" name="message"></textarea>
            <input type="submit" value="Send Message" class="cap_button hubSubmit">
        </fieldset>
    </form>
</div>

我的问题是当我重新打开对话框时状态更新仍然存在。

4

1 回答 1

0

我认为选择器不会像这样工作:

$('.notifications, div:animated', $divDialog).html(''); //this is what I've tried but it doesn't work. 

选择对我来说是空的。尝试将它们分开:

$('.notifications, div:animated').html('');
$divDialog.html('');
于 2012-04-27T16:58:24.370 回答