如何在关闭时删除对话框中的选定元素/文本?

时间:2012-04-27 16:19:46

标签: php jquery html dialog

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

当提交表单时,表单上方会显示一条消息,说明状态是否失败或是否成功。

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>

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

1 个答案:

答案 0 :(得分:0)

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

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

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

$('.notifications, div:animated').html('');
$divDialog.html('');