0

ユーザーがダイアログを閉じるときに、ダイアログ内のテキストを削除しようとしています。ページに複数のダイアログがあり、一部のダイアログにはフォームが含まれています。1 つはユーザーにメッセージを送信するためのもので、もう 1 つはユーザーの詳細を更新するためのフォームです。

フォームが送信されると、ステータスに関するメッセージがフォームの上に表示されます。つまり、失敗したか成功したかを示します。

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 に答える