简体   繁体   中英

Twitter Bootstrap Modal on close

So I have a form in a Twitter Bootstrap modal and I want to trigger an event before the modal is closed. For instance, I want to check if he has any value on any of the inputs. If there is, I use confirm(message) to check if the user wants to lose the data or not. Is there anyway to catch this event?

In the documentation there is those event : Bootstrap modal events

$('#exampleModal').on('hide.bs.modal', function (event) {
    if($(this).find("form input").filter(function(){
        return $(this).val() != "";
    }).size() > 0){
       var r =  confirm("Do you want to proceed");
        if(!r){
            event.preventDefault();
        }

    }
});

Here is a jsfiddle : JsFiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM