admin管理员组

文章数量:1410730

I have a twitter bootstrap modal which I create with the data-tags so no actual javascript.
When I click outside the modal dialog (so on the grey area) it closes, but I want to make sure the fields that are in it are cleared. I tried it with jQuery like so:

$('#modal-form > .modal-dialog').on('blur', function(){
    Utils.clearFields();
});

But I never e in the anonymous function, am I binding the wrong event? Or am I using the wrong selector (I also tried it with "$('#modal-form')")?

Any help on this is highly appreciated.

Thanks

I have a twitter bootstrap modal which I create with the data-tags so no actual javascript.
When I click outside the modal dialog (so on the grey area) it closes, but I want to make sure the fields that are in it are cleared. I tried it with jQuery like so:

$('#modal-form > .modal-dialog').on('blur', function(){
    Utils.clearFields();
});

But I never e in the anonymous function, am I binding the wrong event? Or am I using the wrong selector (I also tried it with "$('#modal-form')")?

Any help on this is highly appreciated.

Thanks

Share Improve this question asked Oct 3, 2013 at 8:51 J.PipJ.Pip 4,6337 gold badges34 silver badges54 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Version 2.3.2 and below

The event handler needs to be placed on hide for version Bootstrap version 2.3.2 and lower

$('#modal-form > .modal-dialog').on('hide', function(){
    Utils.clearFields();
});

If #modal-form has the modal data attributes applied the selector needs modified too:

$('#modal-form').on('hide', function(){
    Utils.clearFields();
});

Documentation http://getbootstrap./2.3.2/javascript.html#modals


Version 3.0

The event handler needs to be placed on hide.bs.modal for version Bootstrap version 3.0:

$("#modal-form").on("hide.bs.modal", function(){
   alert("hiding");
});

Version 3.0 Fiddle: http://jsfiddle/9u5MQ/

Version 3.0 Documentation: http://getbootstrap./javascript/#modals

本文标签: javascriptfire event when losing focus on bootstrapmodalStack Overflow