最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bootstrap Modal doesn't close - Stack Overflow

programmeradmin4浏览0评论

HTML:

<div id="im_modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="Image" aria-hidden="true">
    <div class="modal-footer">
        <a type="button" class="btn pull-left" href="javascript:close_preview()">Cancel</a>
        <button type="submit" class="btn btn-primary pull-left">OK</button>

Javascript:

function close_preview() {
    $("#im_modal").modal("hide");
}

The function close_preview is being called, but doesn't close the modal.

HTML:

<div id="im_modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="Image" aria-hidden="true">
    <div class="modal-footer">
        <a type="button" class="btn pull-left" href="javascript:close_preview()">Cancel</a>
        <button type="submit" class="btn btn-primary pull-left">OK</button>

Javascript:

function close_preview() {
    $("#im_modal").modal("hide");
}

The function close_preview is being called, but doesn't close the modal.

Share Improve this question asked Sep 10, 2013 at 22:21 user2653179user2653179 4231 gold badge8 silver badges22 bronze badges 1
  • Do you have the ids duplicated? – PSL Commented Sep 10, 2013 at 22:32
Add a ment  | 

2 Answers 2

Reset to default 6

It should work, probably the positioning of the function close_preview is not where it is supposed to be. But there is another way without using any methods/events you can add data-dismiss attribute to the button.

<a type="button" class="btn pull-left" data-dismiss="modal">Cancel</a>

Fiddle

For people using Coffeescript with the hide event, be careful with the implicit return. It interrupts the event's propagation. Be sure to return the event.

$('#myModal').on 'hide.bs.modal',(e)->
  //something
  return e
发布评论

评论列表(0)

  1. 暂无评论