2013-02-12 32 views
13

मैं कोड मोडल है:मोडल विंडो बंद करने के बाद कोई ईवेंट कैसे जोड़ें?

<-- Button to trigger modal --> 
<div id="result"></div> 
<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a> 

<-- Modal --> 
<div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
    <div class="modal-header"> 
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
    <h3 id="myModalLabel">Modal header</h3> 
    </div> 
    <div class="modal-body"> 
    <p>One fine body…</p> 
    </div> 
    <div class="modal-footer"> 
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> 
    <button class="btn btn-primary">Save changes</button> 
    </div> 
</div> 

और मैं कोड है, जब करीब Moal खिड़की के बाद किया गया चाहिए:

$('#result').html('yes,result'); 

मुझे बताओ कृपया है कि जब मोडल विंडो बंद करने (करीब या छिपाना) बनाने के लिए एक दूसरा कोड निष्पादित किया?

+0

आप यहां क्या उपयोग कर रहे हैं ??? jquery ui ?? – bipen

+0

bootstrap.js और अधिक http://bootstrap-ru.com/javascript.php#modals –

+0

http://stackoverflow.com/questions/171928/hook-into-dialog-close-event –

उत्तर

17

मुझे उत्तर मिल गया। धन्यवाद सभी लेकिन सही जवाब अगले:

$("#myModal").on("hidden", function() { 
    $('#result').html('yes,result'); 
}); 

यहाँ घटनाक्रम http://bootstrap-ru.com/javascript.php#modals

युपीडी

बूटस्ट्रैप 3.x के लिए hidden.bs.modal का उपयोग की जरूरत:

$("#myModal").on("hidden.bs.modal", function() { 
    $('#result').html('yes,result'); 
}); 
0
$('.close').click(function() { 
    //Code to be executed when close is clicked 
    $('#result').html('yes,result'); 
}); 
+0

यह उत्तर नहीं है बूटस्ट्रैप से संबंधित। – Heitor

41

आप संस्करण का उपयोग कर रहे हैं बूटस्ट्रैप के 3.x, अब यह करने का सही तरीका है:

$('#myModal').on('hidden.bs.modal', function (e) { 
    // do something... 
}) 

और जानने के लिए ईवेंट अनुभाग पर नीचे स्क्रॉल करें।

http://getbootstrap.com/javascript/#modals-usage

इस के लिए अपरिवर्तित ही रहेंगे के सामने प्रकट हो संस्करण 4 रिलीज (http://v4-alpha.getbootstrap.com/components/modal/#events), लेकिन अगर यह होता है मैं प्रासंगिक जानकारी के साथ इस पोस्ट को अद्यतन करने के लिए सुनिश्चित हो जाएगा।

2

कुछ उत्तर उपयोगी हो सकते हैं, खासकर यदि आपके पास गतिशील सामग्री है।

$('#dialogueForm').live("dialogclose", function(){ 
    //your code to run on dialog close 
}); 

या, मोडल खोलते समय, कॉलबैक होता है।

$("#dialogueForm").dialog({ 
       autoOpen: false, 
       height: "auto", 
       width: "auto", 
       modal: true, 
       my: "center", 
       at: "center", 
       of: window, 
       close : function(){ 
        // functionality goes here 
       } 
       }); 

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^