2012-04-27 4 views
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> 

내 문제가 상태 업데이트가 여전히 내가 대화 상자를 다시 열 때 점이다.

+0

당신은 지금 무엇이 문제인지 질문 했습니까? – j08691

+0

죄송합니다, 완전하게 잊어 버렸습니다. –

+0

'$ ('. notifications') .text ('');'와 같이 닫히면 모든 알림을 한꺼번에 비워 두시겠습니까, 아니면이 과도한 단순화입니까? "$ ('. notifications', $ divDialog) .text ('');' –

답변

0

나는 선택기는 다음과 같이 작동합니다 생각하지 않습니다

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

을 선택 다시 빈 나를 위해오고있다. 그들을 분리 해보십시오 :

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

그건 .notifications가있는 페이지의 모든 div를 통과 할 것이고 두 번째 명령문의 양식을 포함하여 대화 상자 안의 모든 것을 지울 것입니다.> _ < –

관련 문제